我有一个任务是创建一个将 deci(-32,768 到 32,767)转换为 bin 的程序。输出必须显示所有 16 位。例如,如果输入是120,那么输出应该是:0000000001111000。我不知道如何反向输出0和1。当我输入 120 时,我得到:0001111000000000。 PS:我正在使用 Pep/8 汇编器和模拟器 (http://code.google.com/p/pep8-1/),它可用于 Mac 和 PC。这是我到目前为止所拥有的:
;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