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

#1 misha1227  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,462
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 ianian112  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 119
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2584
  • View blog
  • Posts: 15,612
  • 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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1