内容发布更新时间 : 2024/11/15 21:57:26星期一 下面是文章的全部内容请认真阅读。
int 21H
; 在StrBuf结尾添加'$' lea bx, StrBuf[2] mov al, StrBuf[1] xor ah, ah add bx, ax
mov byte ptr [bx], '$' ; 换行打印
lea dx, NextLine mov ah, 09H int 21H ; 输出提示 lea dx, Tip2 mov ah, 09H int 21H
; 打印用户输入的字符串 lea dx, StrBuf[2] mov ah, 09H int 21H ; 换行打印
lea dx, NextLine mov ah, 09H int 21H pop dx pop bx pop ax ret
GetLine endp code ends end start
第三题:
stack segment stack dw 512 dup(0) stack ends
data segment X db 0 Y db 0 Z dw 0
NextLine db 0DH, 0AH, '$' TipX db 'Input X:', '$' TipY db 'Input Y:', '$' TipZ db 'Z = ', '$'
InputBuf db 6, ?, 10 dup('$') OutputBuf db 16 dup('$')
Table dw 10000, 1000, 100, 10, 1 data ends
code segment
assume cs:code, ds:data, ss:stack start:
mov ax, data mov ds, ax ; 用户输入 X lea dx, TipX mov ah, 09H int 21H sub sp, 2 call GetNum pop ax mov X, al
lea dx, NextLine mov ah, 09H int 21H
; 用户输入 Y lea dx, TipY mov ah, 09H int 21H sub sp, 2 call GetNum pop ax mov Y, al
lea dx, NextLine mov ah, 09H int 21H mov al, X mov ah, Y push ax call Func pop ax mov Z, ax
push word ptr Z call PutNum Exit:
mov ah, 4CH int 21H
; 参数 8位有符号数X, Y ; 返回值: 16位有符号数 Func proc far push ax push bx push dx push bp mov bp, sp
mov bx, [bp+12] ;bl==X, bh==Y mov al, bl
imul bh ; ax = X*Y mov dx, ax; dx = X*Y ; dx += X mov al, bl cbw
add dx, ax ; dx -= Y mov al, bh cbw
sub dx, ax
mov [bp+14], dx pop bp pop dx pop bx pop ax ret 2 Func endp
; 参数: 无
; 返回值: 8位有符号数 GetNum proc far push ax push bx push cx push dx push bp mov bp, sp
lea dx, InputBuf mov ah, 0AH int 21H mov dl, 10 xor ax, ax
lea bx, InputBuf[2]
mov cl, InputBuf[1] ;设置CX
xor ch, ch
cmp byte ptr InputBuf[2], '-' jne Next_GetNum dec cx inc bx Next_GetNum: mul dl
mov dh, [bx] sub dh, '0' add al, dh inc bx
loop Next_GetNum
cmp byte ptr InputBuf[2], '-' jne End_GetNum mov bl, al xor al, al sub al, bl End_GetNum: xor ah, ah
mov ss:[bp+14], ax lea dx, NextLine mov ah, 09H int 21H pop bp pop dx pop cx pop bx pop ax ret
GetNum endp
; 参数: 16位有符号数 ; 返回值: 无 PutNum proc far push ax push bx push cx push dx push di push si push bp mov bp, sp
mov bx, [bp+18]
cmp word ptr [bp+18], 0
jge P1_PutNum mov bx, 0
sub bx, [bp+18] P1_PutNum: mov cx, 5
lea si, table lea di, OutputBuf Next_PutNum: mov ax, bx mov dx, 0H div word ptr [si] mov bx, dx add al, '0' mov [di], al add si, 2 inc di
loop Next_PutNum
mov byte ptr [di], '$' lea di, OutputBuf[-1] L_PutNum: inc di
cmp byte ptr [di], '0' je L_PutNum
cmp byte ptr [di], '$' jne OutPut_PutNum dec di
OutPut_PutNum:
cmp word ptr [bp+18], 0 jge P2_PutNum dec di
mov byte ptr [di], '-' P2_PutNum: mov dx, di mov ah, 09H int 21H pop bp pop si pop di pop dx pop cx pop bx pop ax ret 2 PutNum endp