Im trying to write a program in LC-3 assembly language that has a hard-coded number between -3000 to +3000 and it should output the binary of the number in 16 bits, and I have no idea how to start, can I get some tips?

## 3 Replies - 11129 Views - Last Post: 29 January 2012 - 04:02 PM

### #1

# LC-3 assembly language...getting the binary of a number?

Posted 26 January 2012 - 12:41 PM

##
**Replies To:** LC-3 assembly language...getting the binary of a number?

### #2

## Re: LC-3 assembly language...getting the binary of a number?

Posted 26 January 2012 - 12:45 PM

Moving to the 'other languages' -> 'assembly' group for better support.

### #3

## Re: LC-3 assembly language...getting the binary of a number?

Posted 27 January 2012 - 11:06 AM

I would use a mask of x1000, read in the highbit say from R1(where your value is stored), AND it with R0, and add x0030 to R0 to account for the number offset, then output the value in R0, and shift R1 to the left.

if the highbit is 1, R0 = 1 + x30 = x31 which will output a 1

if the highbit is 0, R0 = 0 + x30 = x30 which will output a 0

Use a counter to keep track how many times you have shifted it.

if the highbit is 1, R0 = 1 + x30 = x31 which will output a 1

if the highbit is 0, R0 = 0 + x30 = x30 which will output a 0

Use a counter to keep track how many times you have shifted it.

### #4

## Re: LC-3 assembly language...getting the binary of a number?

Posted 29 January 2012 - 04:02 PM

Finally, a dialect I know!

So by hardcoded, you of course mean hex, right? Well, I would store the last digit in another register, convert it to binary, multiply by 8 to shift, wash rinse repeat until original number in question is 0. You do know how to convert hex to binary, right?

So by hardcoded, you of course mean hex, right? Well, I would store the last digit in another register, convert it to binary, multiply by 8 to shift, wash rinse repeat until original number in question is 0. You do know how to convert hex to binary, right?

Page 1 of 1