简体   繁体   中英

How Come LC-3 Is Printing Result In ASCII?

My task is to create a division subroutine that infers that the number that will be divided will be even. This number needs to be divided by two. R1 is the result register (result of N/2), and R0 is the N. My following code is tested with the number 196, we should expect the result to be 98, however, my result printed is "196 / 2 = ü8". The following below is my printed code.

AND R1, R1, #0.  ; Clearing Result reg that could hold values from prior exectutions.

LOOP ADD R0, R0, #-1
ADD R0, R0, #-1 ; Subtracting #1 twice from R0 to divide by two.
ADD R1, R1, #1  ;+1 to R1 for every time R0 can be divided by two, expected to + 98
BRp LOOP ; Loop As Long as R0 Does not = Z or N

RET 

EDIT, IT WORKS!!! BELOW IS THE EDITED SUBROUTINE!!

AND R1, R1, #0

LOOP ADD R1, R1, #1

ADD R0, R0, #-2

BRp LOOP

RET 

Checking if Evenly Divisible by 2 in Assembly

To see if the number can be divided by 2 evenly you just need to check the first bit. To do that, just AND with 1 and check the result.

    AND R0, 1

Dividing by 2 in Assembly

To divide by 2, simply shift out the lowest digit.

    SHR R0, 1

Edit:

I realize now you're interested in an implementation for LC-3. Your implementation looks correct. Since you don't show the printing code it might be an issue there. You can ensure that your print function is working correctly by setting your output register to some known immediate value (such as 98) then trying again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM