0

I need to create a program in MARIE assembly language where I input a HEX and it will convert into a binary. I am trying to implement a left-shifting register. I could use arrays but MARIE does not support accessing single bits of a number. I wonder if it is even possible. Any help is very much appreciated.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • C and other languages also don't support accessing single bits of a number. So, if you can identify an algorithm for doing it in another language, then you can do it in MARIE assembly. – Erik Eidt Apr 18 '22 at 16:22
  • 1
    Left shifting is trivially done with addition. (Right shifting is a bit more involved on a machine like MARIE or LC-3.) – Erik Eidt Apr 18 '22 at 18:30
  • My professor told us to find a way and do this. – Estevão Bittencourt Apr 19 '22 at 19:24
  • When you say "convert to binary", do you mean ASCII text strings holding `'0'` and `'1'` characters that represent a number using base 2? Or do you mean a normal integer in memory or the accumulator? Real computers use binary integers, so a number in a register is already in binary. Either way, you'd probably start by converting the hex string to an integer, unless you just want to work in chunks of 4 bits at once. (With a lookup table of 4-byte strings, indexed by ASCII codes for hex digits, otherwise compare and conditionally subtract another `'a'-10 - '0'` depending on alpha vs. digit) – Peter Cordes Apr 21 '22 at 01:43
  • What I actually need is to input a hex number and shift it to the right or to the left, depending on user input(positive for right shift and negative for left shift). For example, the user inputs hex A, then inputs 3, so it should shift "A" 3 bits to the right. Now, if the user inputs -3, it should shift "A" to the left three bits. Right shifting is easy, but left shifting is really hard, because there is no way to access single bits of a number in MARIE. – Estevão Bittencourt Apr 25 '22 at 15:28

0 Answers0