0

I'm confused at the wording of two questions c. Give the LC-3 representation of -22 expressed as hexadecimal in a 16 bit word. d. What integer does the 16 bits FF1A represent in the LC-3?

for c) is it just asking for -22 in hexadecimal which is -0x16?

and for d) is the question just asking for the hexadecimal to base 10 conversion? or to base 2 since lc3 uses 16bits 2s comps?

rahulchawla
  • 170
  • 1
  • 3
  • 20
  • c) no, it's asking for the two's complement value. d) yes, to decimal, it's unclear whether it wants signed or unsigned but probably the former. – Jester Dec 06 '17 at 01:23
  • so for c) i can get 22 in in base 2 and gets the 2s complement and then convert that to hex correct? @Jester – rahulchawla Dec 06 '17 at 01:45
  • c) you should end with `FFEA`, make sure your "get the 2s complement" skill is up to it (to verify quickly, if you have desktop like KDE, just open the launcher (Alt+F2 in KDE) and write "=0xFFEA-65536" => shows -22) ... for d) the base2 from base16 is trivial, if you understand that single digit in base16 is exactly 4 bits, you can translate it almost instantly in head. So it's more likely they expect base10 and signed, on paper `FF1A`: 15*16^3 + 15*16^2 + 1*16 + 10 = 65306 unsigned and by -65536 => -230 signed. You can also do only "int8_t" shortcut 0x1A-256=-230 (because upper 16b is FF). – Ped7g Dec 06 '17 at 03:06
  • question with c) when I flip 0000 0000 0001 0110 and then add 1 to get the negative im ending up with 1111 1111 1110 1000 am i suppose to carry a 1 from 1+1? I asssume so because of binary addition sorry just confusing myself @Ped7g – rahulchawla Dec 06 '17 at 17:44
  • flipped value ends 1001, so +1 => 1010 of course... +1 without carrying up is "xor", not "+". ... BTW, other way to validate for small value... take like "4" ... flip it ... add 1 .... now keep adding 1 until zero (should be four times, because -4 +1 +1 +1 +1 = 0) ... (and the value should be `-4 == 0xFFFC`) – Ped7g Dec 06 '17 at 20:14
  • @Ped7g just wondering about this line "-65536 => -230 signed." but when you flip the bits and add 1 of 65536 in binary you get +230 signed - did you make a typo? – rahulchawla Dec 10 '17 at 03:10
  • @rahulchawla That was meant as: `65306 - 65536 = -230` .. the `65306` is `0xFF1A`. The `-65536` is a simple way how to reinterpret the 16b unsigned value as 16b signed value with calculator, when you are verifying some code or memory dump (like I have in linux available launcher under Alt+F2, which is capable also of calculations, so when I see in debugger the `ax` contains `FF1A`, I can just write `=0xFF1A-65536` (shows -230 result) to see what is that value in signed short way. Take 0xFF1A, flip bits, add one => you should get indeed 230. (neg(-230) = +230). ("magic" 65536 = 0x10000 = 2^16) – Ped7g Dec 10 '17 at 11:49

0 Answers0