Hardware Reference
In-Depth Information
EXIT = 1
! 1 define the value of EXIT
PRINTF = 127
! 2 define the value of PRINTF
.SECT .TEXT
! 3 start the TEXT segment
inpstart:
! 4 define label inpstart
MOV BP,SP
! 5 save SP in BP
PUSH vec2
! 6 push address of vec2
PUSH vec1
! 7 push address of vec1
MOV CX,vec2-vec1
! 8 CX = number of bytes in vector
SHR CX,1
! 9 CX = number of words in vector
PUSH CX
! 10 push word count
CALL vecmul
! 11 call vecmul
MOV (inprod),AX
! 12 move AX
PUSH AX
! 13 push result to be printed
PUSH pfmt
! 14 push address of format string
PUSH PRINTF
! 15 push function code for PRINTF
SYS
! 16 call the PRINTF function
ADD SP,12
! 17 clean up the stack
PUSH 0
! 18 push status code
PUSH EXIT
! 19 push function code for EXIT
SYS
! 20 call the EXIT function
vecmul:
! 21 start of vecmul(count, vec1, vec2)
PUSH BP
! 22 save BP on stack
MOV BP,SP
! 23 copy SP into BP to access arguments
MOV CX,4(BP)
! 24 put count in CX to control loop
MOV SI,6(BP)
! 25 SI = vec1
MOV DI,8(BP)
! 26 DI = vec2
PUSH 0
! 27 push 0 onto stack
1:
LODS
! 28 move (SI) to AX
MUL (DI)
! 29 multiply AX by (DI)
ADD -2(BP),AX
! 30 add AX to accumulated value in memory
ADD DI,2
! 31 increment DI to point to next element
LOOP 1b
! 32 if CX > 0, go back to label 1b
POP AX
! 33 pop top of stack to AX
POP BP
! 34 restore BP
RET
! 35 return from subroutine
.SECT .DATA ! 36 start DATA segment
pfmt: .ASCIZ "Inner product is: %d\n" ! 37 define string
.ALIGN 2
! 38 force address even
vec1:.WORD 3,4,7,11,3
! 39 vector 1
vec2:.WORD 2,6,3,1,0
! 40 vector 2
.SECT .BSS
! 41 start BSS segment
inprod: .SPACE 2
! 42 allocate space for inprod
Figure C-14. The program vecprod.s .
 
Search WWH ::




Custom Search