Tasm汇编语言浮动

时间:2017-04-15 01:31:11

标签: assembly tasm

自从我开始寻找问题的答案已经过去了3天,但我仍然没有任何解决问题的运气。

Tasm文件是一个迷你计算器,它输出int数字,我需要输出浮点数,任何帮助将不胜感激。

以下是代码:

.model small
.stack 100h

.data
msg1 db 13,10,13,10, "Enter 1st Number : $"
msg2 db 13,10, "Enter 2nd Number : $"
msgEr db 13,10, "Error $"
msgCh db 13,10, "Press A to ADD , S to SUBTRACT ,D to MULTIPLY, F to DIVIDE, X to EXIT : $ "
msgSum db 13,10,13,10, "Sum is : $"
msgDif db 13,10,13,10, "Difference is : $"
msgDiv db 13,10,13,10, "Quotient is : $"
msgMul db 13,10,13,10, "Product is : $"
tmp     db ?


.code

start:
mov ax, @data
mov ds, ax

lea dx, msg1
mov ah, 09h
int 21h
mov bx, 0

start1:
mov ah, 01h
int 21h
cmp al,0dh      
je next1
mov ah,0        
sub al,30h      
push ax         
mov ax,10d      
mul bx          
pop bx          
add bx,ax       
jmp start1      




next1:
push bx
lea dx,msg2
mov ah,09h
int 21h

mov bx,0


start2:
mov ah,01h
int 21h
cmp al,0dh
je choice
mov ah,0
sub al,30h
push ax
mov ax,10d
mul bx
pop bx
add bx,ax 
jmp start2


choice:
lea dx, msgCh
mov ah, 09h
int 21h

mov ah, 01h
int 21h

cmp al,'f'
je dividing

cmp al,'a'  
je adding

cmp al,'s'
je subtracting

cmp al,'d'
je multiplying

cmp al,'x'
mov ah, 4ch
int 21h

error:
lea dx,msgEr
mov ah,09h
int 21h 
jmp start


dividing: 
pop ax
div bx
push ax
lea dx,msgDiv
mov ah,09h 
int 21h 
pop ax
mov cx,0
mov dx,0
mov bx,10d
jmp break

adding:     
pop ax
add ax,bx   
push ax
lea dx,msgSum   
mov ah,09h
int 21h 
pop ax
mov cx,0
mov dx,0
mov bx,10d
jmp break   

multiplying: 
pop ax
mul bx      
push ax     
lea dx,msgMul   
mov ah,09h
int 21h 
pop ax
mov cx,0
mov dx,0
mov bx,10d
jmp break


subtracting: 
pop ax
sub ax,bx 
push ax
lea dx,msgDif
mov ah,09h
int 21h 
pop ax
mov cx,0
mov dx,0
mov bx,10d

break:
div bx
push dx
mov dx,0
inc cx
or ax,ax 
jne break 

ans:        
pop dx
add dl,30h
mov ah,02h
int 21h
loop ans

jmp start

end start

1 个答案:

答案 0 :(得分:0)

打印整个分割结果十进制

我的代码中没有看到任何浮点运算。因此,我假设你只对打印出一个分区的结果感兴趣,比如10/3 = 3.33333。该方法类似于笔和纸方法:您重复向余数添加0(=乘以10)并除以这个新数字。

redmond.calendars.picker.css生成一个整数部分和一个余数。整数部分将被转换为此处和其他地方描述的任何整数。余数代表小数部分。 Mukltiply与10并做一个师。您将获得DIV中小数部分的十进制数字和可以除以的新余数等等。如果剩余部分为0或您失去兴趣,则完成工作。

10,000 / 7的示例:

AX