Question: LC3 assembly code bug The code works perfect except it outputs a space at the end of the binary output. anyone can fix it so
LC3 assembly code bug
The code works perfect except it outputs a space at the end of the binary output. anyone can fix it so it does not have a space at the end?
ex: value is x0 I want it to output "0000 0000 0000 0000//n" but it outputs "0000 0000 0000 0000 //n" <--get rid of space at the end.
I want to change code as little as possible, thumbs up for any quick answer that works
code:
.ORIG x3000
;-------------
;Instructions
;-------------
LD R1, Convert ; R6 <-- Address pointer for Convert
;LDR R1, R6, #0 ; R1 <-- VARIABLE Convert
;-------------------------------
;ENTER CODE HERE
;--------------------------------
;clear R5
AND R5, R5, #0
;set R5
ADD R5, R5, #15
;clear R3
AND R4, R4, #0
;Set R4.
ADD R4, R4, #4
;loop
LOOP
;Add R4
ADD R4, R4, #0
;Go to nextnibble
BRp NEXTNIBBLE
;load ' '
LEA R0, free ;this is where the issue is, i want the space every 4 numbers but not after the 16th/last one
; display space
TRAP x22
;clear R4
AND R4, R4, #0
;Set R4
ADD R4, R4, #4
;Update R5
ADD R5, R5, #0
;Jump to end next nibble
BR ENDNEXTNIBBLE
;label next nibble
NEXTNIBBLE
;Get R1
ADD R1, R1, #0
;jump to label IFSTAMT if R1 is negative
BRn IFSTAMT
; if positive then print 0
LEA R0, stringzero
; instruction to print 0
TRAP x22
;jump to ENDIFSTAMT
BR ENDIFSTAMT
;label IFSTAMT
IFSTAMT
;Load string 1
LEA R0, stringone
;Display 1
TRAP x22
;label ENDIFSTAMT
ENDIFSTAMT
;Move to next bit
ADD R1, R1, R1
;Decrease R5
ADD R5, R5, #-1
;Decrease R4
ADD R4, R4, #-1
;label ENDNEXTNIBBLE
ENDNEXTNIBBLE
;go to loop
BRzp LOOP
;load new line
LEA R0, newLine
;print newline
PUTS
;Stop the program
HALT
;---------------
;Data
;---------------
;Convert_addr .FILL x3040 ; The address of where to find the data
count .FILL #16
count2 .FILL #4
stringone .STRINGZ "1"
stringzero .STRINGZ "0"
free .STRINGZ " "
newLine .STRINGZ " "
;.ORIG x3040 ; Remote data
Convert .FILL xABCD ; <----!!!NUMBER TO BE CONVERTED TO BINARY!!!
;---------------
;END of PROGRAM
;---------------
.END
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
