汇编语言(assembly language)实现方程的计算
程序员文章站
2022-04-12 23:32:02
...
~~
##汇编语言(assembly language)实现方程的计算
*题目描述:y=4x-5,输入一个十进制一位的x,输出y
其实是有三种做法的。。
2.
data segment
m1 db 0dh,0ah,'y=4*x-5;x=','$'
m2 db 0dh,0ah,'y=','$'
results db ?,?,"$"
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
input:
lea dx,m1
mov ah,9
int 21h
mov ah,1
int 21h
cmp al,1bh
je exit
and al,00001111b ;根据ascii,减去30h
mov bl,4
mul bl
sub ax,5
mov cx,ax
lea dx,m2
mov ah,9
int 21h
mov ax,cx
cmp ax,8000h
ja flag
temp:
mov bl,10
div bl ;al商,ah余ax商,dx余
or al,00110000b
or ah,00110000b
cmp al,'0'
je s2
jne s1
flag:
mov ah,2
mov dl,'-'
int 21h
mov ax,cx
neg ax
jmp temp
s1:
mov results,al
mov results+1,ah
jmp output2
s2:
mov results,ah
mov results+1,'$'
output2:
mov ah,9
lea dx,results
int 21h
jmp input
exit:
mov ah,4ch
int 21h
code ends
end start
3
data segment
m1 db 0dh,0ah,'y=4*x-5;x=','$'
m2 db 0dh,0ah,'y=','$'加粗样式
r0 db 0dh,0ah,'y=-5','$'
r1 db 0dh,0ah,'y=-1','$'
results db ?,?,"$"
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
input:
lea dx,m1
mov ah,9
int 21h
mov ah,1
int 21h
cmp al,1bh
je exit
cmp al,'1'
je output1
cmp al,'0'
je output0
and al,00001111b ;根据ascii,减去30h
mov bl,4
mul bl
sub ax,5
mov bl,10
div bl ;al商,ah余ax商,dx余
or al,00110000b
or ah,00110000b
cmp al,'0'
je s2
s1:
mov results,al
mov results+1,ah
jmp output2
s2:
mov results,ah
mov results+1,'$'
jmp output2
output0:
lea dx,r0
mov ah,9
int 21h
jmp input
output1:
lea dx,r1
mov ah,9
int 21h
jmp input
output2:
mov ah,9
lea dx,m2
int 21h
mov ah,9
lea dx,results
int 21h
jmp input
exit:
mov ah,4ch
int 21h
code ends
end start