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

Page 1 of 1

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

#1 misha1227

Reputation: 0
• Posts: 8
• Joined: 11-October 11

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

Posted 26 January 2012 - 12:41 PM

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?
Is This A Good Question/Topic? 0

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

#2 modi123_1

• Suitor #2

Reputation: 6470
• Posts: 23,517
• Joined: 12-June 08

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 ianian112

• D.I.C Regular

Reputation: 118
• Posts: 378
• Joined: 28-November 09

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.

#4 NeoTifa

• ¿Dónde están mis pantalones?

Reputation: 1971
• Posts: 14,483
• Joined: 24-September 08

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?