不使用乘法或除法输入和显示32位数

时间:2017-09-22 14:43:09

标签: assembly binary x86-16 emu8086

.model small
.stack 100h
.data 
tempax dw ?
tempdx dw ?
num dw ?
.code

.startup
push '@'      ; initializing values
mov tempax,0
mov tempdx,0
mov num,0
mov cx,0
mov dx,0


read:     ; taking input
mov ah,01h
int 21h
mov ah,0
cmp al,13
je disp
Mov ch, 0
sub al,48
mov cl,al
mov ax,0
mov ax,num

clc ;clearing flag as rcl shifts value of flag to lsb
rcl ax,1
rcl dx,1
mov tempax,ax ;          save value of once shifted                     register as we to use it ahead

mov tempdx,dx ;      user 2 register to         accommodate 32 bit number 

clc

rcl ax,1
rcl dx,1
clc

rcl ax,1
rcl dx,1
clc

add ax,tempax   ; adding once shifted register with thrice shifted register 
adc dx,tempdx ; tc of any carry
clc
add al,cl    ; now adding number taken from user to result. 
adc dl,0 ; again taking care of carry
mov num,ax ; saving ax to num 
jmp read

disp:
mov ax,num 

mov bx,0 ; bx is used to save the remainder 
add bx,48 


disp1:


clc
rcr dx,1
rcr ax,1
rcl bx,1 ;shifts value of carry flag to bx

cmp ax,tempax
je poppy ; to stop loop
mov tempax,ax ; saving once shifted register
mov tempdx,dx
clc

rcr dx,1
rcr ax,1
rcl bx,1

clc

rcr dx,1
rcr ax,1
rcl bx,1

clc
xchg tempax,ax  
sub ax,tempax ;    subtracting once shifted with 3 times shifted register 

xchg tempdx,dx
sub dx,tempdx

push bx ; as bits are shifted they are saved in bx abd then pushed to stack

jmp disp1


poppy:

pop dx 

cmp dx,'@'; end of stack check
je exit
sub dx,48  ;converting back to ascii
mov ah,02h
int 21h
jmp poppy


exit:
mov ah,04ch
mov al,0
int 21h
end

首先,我从用户输入一个带有中断功能的输入01h将其与输入键进行比较(输入的代码为13)然后我将ASCII值转换为其绝对值。如果我们左移3次并将其添加到左移的数字,一旦它相当于数字* 10。之后我添加用户输入的数字。如果我想显示输入,则1,2变为12.now必须通过分割它们并将其发送到堆栈来取出每个字符。然后使用poppy函数显示数字,但它显示一些乱码字符。我尝试添加并减去48即转换为ASCII。该程序运行时没有语法错误,有一个我无法找到的逻辑错误

0 个答案:

没有答案