How would I go about converting a given 16 bit string of 1s and 0s into Assembly language, and then output it onto the console? For example: Convert 0001001010000011 into "ADD R1 R2 R3".
Asked
Active
Viewed 1,202 times
2
-
That depends on the instruction set, and what do you mean by "16-bit string of 1s and 0s"? What's the character-encoding? Please provide more details. – Dai Apr 28 '15 at 22:07
-
@Dai It says LC3 quite clearly ;) The instructions are 16 bit, he wants to write a disassembler. Better question is, does the disassembler also have to be in LC3 assembly? – Jester Apr 28 '15 at 22:09
-
1Sorry! I'm in a basic Computer Engineering class and we've been spending the whole year learning LC-3 assembly language. So the code would use the LC-3 instruction set (ADD, NOT, LDR, STR, etc...) with registers R0 to R7. For the 16-bit string of 1s and 0s, I provided an example. Thanks! – Alex Laferriere Apr 28 '15 at 22:15
-
@Jester Yes exactly I need to write a disassembler, and it all has to be written in LC-3 assembly. – Alex Laferriere Apr 28 '15 at 22:16
-
And where did you get stuck? You just need to chop off the first 4 bits which identify the instruction, then write the 16 functions that can decode the appropriate one. – Jester Apr 28 '15 at 22:26
-
Well I know how to chop off the leftmost bit and analyze that, but I cant figure out how to chop off the 4 leftmost bits. Then I figured I would just write a separate subroutines for each of the 16 different instructions like you suggested, and jump to a certain subroutine if, for example, the value of the 4 leftmost bits = #1. (Jump to the ADD subroutine). – Alex Laferriere Apr 28 '15 at 22:33
-
Chop off the first bit, convert it to 0/1 by subtracting the ascii code of `0`, then shift it left (add it to itself) then bring in the next bit and so on. – Jester Apr 28 '15 at 22:36
-
@Jester Can you take a look at this? http://stackoverflow.com/questions/29981266/how-to-increment-a-letter-in-string-in-lc3 – committedandroider May 01 '15 at 05:28