设array是10个元素的数组,每个元素8位数据。试用子程序计算数组元素的校验和,并将结果存入变量result中。所谓校验和是指不记进位的累加用于检查信息的正确性

子程序的参数传递:

1.用寄存器传递参数
data segment
    count equ 10
    array db 12h,25h,0f0h,0a3h,3,68h,71h,0cah,0ffh,90h
    result db ?
data ends
code segment
assume cs:code,ds:data
start:
    mov bx,offset array
    mov cx,count
    call checksuma
    mov result,al
    mov ah,4ch
    int 21h
checksuma proc
    xor al,al
suma:add al,[bx]
    inc bx
    loop suma
    ret
checksuma endp
code ends
end start

2.使用变量传递参数

data segment
    count equ 10
    array db 12h,25h,0f0h,0a3h,3,68h,71h,0cah,0ffh,90h
    result db ?
data ends
code segment
assume cs:code,ds:data
start:
    call checksuma
    mov ah,4ch
    int 21h
checksuma proc
    push ax
    push bx
    push cx
    xor al,al
    mov bx,offset array
    mov cx,count
suma:add al,[bx]
    inc bx
    loop suma
    mov result,al
    pop cx
    pop bx
    pop ax
    ret
checksuma endp
code ends
end start

3.使用堆栈传递参数

data segment
    count equ 10
    array db 12h,25h,0f0h,0a3h,3,68h,71h,0cah,0ffh,90h
    result db ?
data ends
code segment
assume cs:code,ds:data
start:
    mov ax,offset array
    push ax
    mov ax,count
    push ax
    call checksuma
    add sp,4;主程序平衡堆栈
    mov result,al
    mov ah,4ch
    int 21h
checksuma proc
    push bp
    mov bp,sp
    push bx
    push cx
    mov bx,[bp+6];数组的偏移地址
    mov cx,[bp+4];数组的元素个数
    xor al,al
suma:add al,[bx]
    inc bx
    loop suma
    pop cx
    pop bx
    pop bp
    ret
checksuma endp
code ends
end start

设array是10个元素的数组,每个元素8位数据。试用子程序计算数组元素的校验和,并将结果存入变量result中。所谓校验和是指不记进位的累加用于检查信息的正确性