| 
 | 
 
 
发表于 2021-10-20 22:43:46
|
显示全部楼层
 
 
 
- assume cs:code, ds:data
 
  
- data segment
 
 -         a       db 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
 
 -         b       db 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
 
 -         _c      db 15, 25, 35, 45, 55, 65, 75, 85, 95, 105
 
 -         sum     dw 3 dup(0)
 
 -         average db 3 dup(0)
 
 - data ends
 
  
- code segment
 
  
- ; uint16_t function_sum(uint8_t array[], uint16_t size);
 
 - ; array:        bx
 
 - ; size:         ax
 
 - function_sum:
 
 -         push    bx
 
 -         push    dx
 
 -         push    si
 
 -         mov     si, bx
 
 -         add     si, ax
 
 -         xor     dx, dx
 
 -         xor     ax, ax
 
 - L0:
 
 -         mov     al, [bx]
 
 -         add     dx, ax
 
 -         inc     bx
 
 -         cmp     bx, si
 
 -         jb      L0
 
 -         mov     ax, dx
 
 -         pop     si
 
 -         pop     dx
 
 -         pop     bx
 
 -         ret
 
  
- ; uint8_t function_average(uint16_t sum, uint16_t size);
 
 - ; sum:  ax
 
 - ; size: bx
 
 - function_average:
 
 -         push    cx
 
 -         push    dx
 
 -         mov     cx, ax
 
 -         xor     dx, dx
 
 -         div     bx
 
 -         mov     ah, ch
 
 -         pop     dx
 
 -         pop     cx
 
 -         ret
 
  
- start:
 
 -         mov     ax, data
 
 -         mov     ds, ax
 
 -         
 
 -         mov     bx, offset a
 
 -         mov     ax, 10
 
 -         call    function_sum
 
 -         mov     bx, offset sum
 
 -         add     bx, 0
 
 -         mov     [bx], ax
 
 -         
 
 -         mov     bx, offset b
 
 -         mov     ax, 10
 
 -         call    function_sum
 
 -         mov     bx, offset sum
 
 -         add     bx, 2
 
 -         mov     [bx], ax
 
 -         
 
 -         mov     bx, offset _c
 
 -         mov     ax, 10
 
 -         call    function_sum
 
 -         mov     bx, offset sum
 
 -         add     bx, 4
 
 -         mov     [bx], ax
 
 -         
 
 -         mov     bx, offset sum
 
 -         add     bx, 0
 
 -         mov     ax, [bx]
 
 -         mov     bx, 10
 
 -         call    function_average
 
 -         mov     bx, offset average
 
 -         add     bx, 0
 
 -         mov     [bx], al
 
 -         
 
 -         mov     bx, offset sum
 
 -         add     bx, 2
 
 -         mov     ax, [bx]
 
 -         mov     bx, 10
 
 -         call    function_average
 
 -         mov     bx, offset average
 
 -         add     bx, 1
 
 -         mov     [bx], al
 
 -         
 
 -         mov     bx, offset sum
 
 -         add     bx, 4
 
 -         mov     ax, [bx]
 
 -         mov     bx, 10
 
 -         call    function_average
 
 -         mov     bx, offset average
 
 -         add     bx, 2
 
 -         mov     [bx], al
 
 -         
 
 -         mov     ax, 4c00h
 
 -         int     21h
 
 - code ends
 
 - end start
 
 
  复制代码 |   
 
 
 
 |