2012-04-23 43 views
1

我有一個任務來創建一個程序,將deci(-32,768到32,767)轉換爲bin。輸出必須顯示全部16位。例如,如果輸入是120,輸出應該是:0000000001111000.我不知道如何反向輸出0和1。當我輸入120時,我得到:0001111000000000. P.S:我使用Pep/8彙編器和模擬器(http://code.google.com/p/pep8-1/),它可用於Mac和PC。 這是我到目前爲止有:Deci到bin轉換器(pep/8彙編器和模擬器)

;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

您現在右移和測試,在攜帶結束位。如果你換一種方式會發生什麼?

+0

左移乘以2. – Rndpbs 2012-04-23 02:58:05

+0

哦,我的壞,我找到了你。非常感謝。 – Rndpbs 2012-04-23 03:02:22