Assembly Deci-to-bin转换器(Pep/8汇编程序和模拟器)
我的任务是创建一个程序,将deci(-32768到32767)转换为bin。输出必须显示所有16位。例如,如果输入为120,则输出应为:000000000 1111000。我不知道如何反向输出0和1。当我输入120时,我得到:000111000000000。 附言:我正在使用Pep/8汇编程序和模拟器(http://code.google.com/p/pep8-1/),适用于Mac和PC。 这就是我到目前为止所做的:Assembly Deci-to-bin转换器(Pep/8汇编程序和模拟器),assembly,pep8-assembly,Assembly,Pep8 Assembly,我的任务是创建一个程序,将deci(-32768到32767)转换为bin。输出必须显示所有16位。例如,如果输入为120,则输出应为:000000000 1111000。我不知道如何反向输出0和1。当我输入120时,我得到:000111000000000。 附言:我正在使用Pep/8汇编程序和模拟器(http://code.google.com/p/pep8-1/),适用于Mac和PC。 这就是我到目前为止所做的: ;Pavel; Assignment 3 BR main
;Pavel; Assignment 3
BR main ;Branch to MAIN
num: .BLOCK 2 ;Input variable
flag: .BLOCK 2 ;C flag
limit: .BLOCK 2 ;Loop LIMIT
main: LDA 0, i ;Clear Accumulator
DECI num, d ;Input
loop: LDA limit, d ;Load loop LIMIT
CPA 16, i ;Compare LIMIT to 16
BREQ exit ;If LIMIT == 16, branch to EXIT. Done converting.
LDA num, d ;Load NUM
ASRA ;Shift NUM to the right (division by 2)
STA num, d ;Store NUM after division
if: MOVFLGA ;Load flags to Accumulator
BRC else ;If C == 1, branch to ELSE
DECO 0, i ;Output 0
LDA limit, d ;Load LIMIT
ADDA 1, i ;Add 1 to LIMIT
STA limit, d ;Store LIMIT
BR loop ;Branch to LOOP
else: DECO 1, i ;Output 1
LDA limit, d ;Load LIMIT
ADDA 1, i ;Add 1 to LIMIT
STA limit, d ;Store LIMIT
BR loop ;Branch to LOOP
exit: CHARO ' ', i ;Outputs space
STOP
.END
您现在正在右移并测试最终进位的位。如果你换成另一种方式会发生什么?左移乘以2。哦,糟糕,我抓到你了。谢谢。