下课了发现贺老师那边还没下课,趁机蹭了一波课,顺便蹭了个上机实验,美滋滋(๑•ᴗ•๑)♡
版本一:预设bl为8
TITLE ketang(EXE) Use a subroutine to calculate y = x ^ 4. stacksg segment para 'Stack' db 8 dup(0) stacksg ends codesg segment para 'Code' main proc far assume cs:codesg,ss:stacksg mov ax,stacksg mov ss,ax mov sp,16 ;Set the stack segment. xor bx,bx mov ax,1 mov bl,8 call power ;Call the subroutine. mov ax,4c00h int 21h main endp ;---------------------------------------- ;Function: Calculate y = x ^ 4. ;Entry parameter: register BL. ;Export parameters: register AX. ;----------------------------------------- power proc near push cx push bx mov cx,4 .repeat mul bx .untilcxz pop cx pop bx ret power endp codesg ends end main
版本二:
TITLE ketang(EXE) Use a subroutine to calculate y = x ^ 4. data segment para 'Code' x db 1,2,3,4,5,6,7,8 y dw 0,0,0,0,0,0,0,0 data ends stacksg segment para 'Stack' db 8 dup(0) stacksg ends codesg segment para 'Code' main proc far assume cs:codesg,ss:stacksg,ds:data mov ax,data mov ds,ax mov ax,stacksg mov ss,ax mov sp,16 ;Set the stack segment. lea bp,x lea si,y mov cx,8 .repeat push cx mov ax,1 xor bx,bx mov bl,ds:[bp] inc bp mov cx,4 .repeat call power ;Call the subroutine. .untilcxz mov ds:[si],ax add si,2 pop cx .untilcxz mov ax,4c00h int 21h main endp ;Function: Calculate y = x ^ 4. ;Entry parameter: register BL. ;Export parameters: register AX. power proc near push bx mul bx pop bx ret power endp codesg ends end main
版本三:
TITLE ketang(EXE) Use a subroutine to calculate y = x ^ 4. data segment para 'Code' x db 1,2,3,4,5,6,7,8 y dw 0,0,0,0,0,0,0,0 data ends stacksg segment para 'Stack' db 8 dup(0) stacksg ends codesg segment para 'Code' main proc far assume cs:codesg,ss:stacksg,ds:data mov ax,data mov ds,ax mov ax,stacksg mov ss,ax mov sp,16 ;Set the stack segment. lea si,x lea di,y call power mov ax,4c00h int 21h main endp ;Function: Calculate y = x ^ 4. ;Entry parameter: register SI,DI ;Export parameters: NULL. power proc near push bx push ax mov cx,8 .repeat push cx mov ax,1 xor bx,bx mov bl,ds:[si] inc si mov cx,4 .repeat mul bx .untilcxz mov ds:[di],ax add di,2 pop cx .untilcxz pop bx pop ax ret power endp codesg ends end main
版本四:
主程序:
TITLE ketang(EXE) Use a subroutine to calculate y = x ^ 4. extrn power:far data segment para 'Code' x db 1,2,3,4,5,6,7,8 y dw 0,0,0,0,0,0,0,0 data ends stacksg segment para 'Stack' db 8 dup(0) stacksg ends codesg segment para 'Code' main proc far assume cs:codesg,ss:stacksg,ds:data mov ax,data mov ds,ax mov ax,stacksg mov ss,ax mov sp,16 ;Set the stack segment. lea si,x lea di,y call far ptr power mov ax,4c00h int 21h main endp codesg ends end main
子程序
;Function: Calculate y = x ^ 4. ;Entry parameter: register SI,DI ;Export parameters: NULL. public power codesg segment para 'Code' power proc assume cs:codesg push bx push ax mov cx,8 .repeat push cx mov ax,1 xor bx,bx mov bl,ds:[si] inc si mov cx,4 .repeat mul bx .untilcxz mov ds:[di],ax add di,2 pop cx .untilcxz pop bx pop ax retf power endp codesg ends end power