随机数相减 汇编语言
发布网友
发布时间:2022-04-22 08:24
我来回答
共1个回答
热心网友
时间:2022-06-18 14:10
;小学生算术练习软件
;
Output macro mess
mov dx,offset mess
mov ah,9
int 21h
endm
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
START:
push cs
pop ds
Begin: Output string
getkey: mov ah,0
int 16h
cmp al,0dh
jz exit
cmp al,'1'
jb getkey
cmp al,'4'
ja getkey
mov ah,0eh
int 10h
and ax,0fh
mov bx,ax
dec bx
shl bx,1
call word ptr Table[bx]
mov Z,al
call Change
jmp jsq
@warn: Output error
jsq: Output buffer
call shuru
cmp al,Z
jnz @warn
Output yes
jmp Begin
exit: mov ah,4ch
int 21h
csh: call @Rnd
mov X,al
call @Rnd
mov Y,al
ret
@Rnd: push dx
xor dx,dx
in ax,40h
div cx
mov al,dl
test al,al
jz @Rnd
pop dx
ret
jiafa: ;"+"加法
mov fh,'+'
mov cx,100
call csh
mov al,X
add al,Y
ret
jianfa: ;"-"!!!随机数相减!!!
mov fh,'-'
mov cx,100
call csh
mov al,X
cmp al,Y
jnb jf1
xchg al,Y
mov X,al
jf1:
sub al,Y
ret
chenfa: ;"*"乘法
mov fh,'*'
mov cx,10
call csh
mov al,X
mul Y
ret
Chufa: ;"/" 除法
mov fh,'/'
mov cx,10
call csh
mov al,X
cbw
mov cl,Y
mov ch,0
cmp ax,cx
jnb cf1
xchg ax,cx
mov X,al
mov Y,cl
cf1:xor dx,dx
div cx
ret
Asc:mov al,al
aam
or ax,3030h
xchg al,ah
ret
Change:
mov al,X
call Asc
mov X1,ax
mov al,Y
call Asc
mov Y1,ax
mov al,Z
call Asc
mov Z1,ax
ret
shuru proc
push bp
push cx
push bx
xor bp,bp
mov bx,10
mov cx,3
input:
mov ah,0 ;键盘输入数据
int 16h
cmp al,0dh ;以回车结束输入
jz ok
cmp al,'0' ;只允许输入0~9
jb input
cmp al,'9'
ja input
mov ah,0eh ;显示有效输入
int 10h
and ax,000fH ;化ASCII为HEX
xchg ax,bp
mul bx ;扩大10倍
add bp,ax ;加一位
loop input
ok:mov ax,bp ;数值结果放入ax
;恢复用到的寄存器
pop bx
pop cx
pop bp
ret
shuru endp
X db ?
Y db ?
Z db ?
N db ?
buffer db 0dh,0ah,9
X1 dw ?
fh db ?
Y1 dw ?
db '= $'
Z1 dw ?
Yes db 9,'Correct!$'
error db 9,'Error!$'
string db 0dh,0ah,9,'Menu: '
db 9,'1.Jia fa 2.Jian fa Chen fa 4.Chu fa',0dh,0ah
db 9,'Choice(1-4),enter to quit: $'
Table dw jiafa,jianfa,chenfa,Chufa
CODE ENDS
END START