This is from an old homework question and answer key I'm studying for an upcoming test. I'm unsure about the answer.

Write the following code in MARIE assembly language:

X := 1
While X < 10 do
  X := X+1; 

Answer:

Assembly code:

000  Load 009
001  Add 00B
002  Skipcond 000
003  Jump 008
004  Load 009
005  Add 00A
006  Store 009
007  Jump 000
008  Halt
009  0001
00A  0001
00B  FFF6

Is this answer right or did she make a typo? You Load 0009, then Add FFF6?
How is that less than 10? How does that satisfy Skipcond? It seems like its just FFF6 + 0001 which will send the program to the halt statement without ever executing that loop. And when does the number 10 (for the loop condition) even come into play?
Posted on 2008-10-07 05:01:13 by angrynapkin
Note that the highest bit is SET, for signed values that would indicate it is a negative value.
FFF6, if you think about it, is actually -10 !!! MINUS TEN !!!

:)
Posted on 2008-10-07 05:09:54 by Homer
Thanks for confirming my suspicions, I was wondering if something like that was the deal. Thank you!
Posted on 2008-10-07 11:19:42 by angrynapkin
The asm code is perfect.
"while(X<10)"  means "while(X-10<0)".
Posted on 2008-10-07 13:16:11 by Ultrano
Yeah. It's just, interesting going from high level language to machine and assembly.
Posted on 2008-10-07 14:19:18 by angrynapkin
Can anyone point me towards a primer with 2's complement using hex numbers? I've done it with binary.
Posted on 2008-10-07 14:40:54 by angrynapkin
Well, the only difference is that quads of bits make up 1 hex digit.

0 - 0000
1 - 0001
...
7 - 0111
8 - 1000
9 - 1001
A - 1010
B - 1011
...
E - 1110
F - 1111

That's basically it ^^

Thing to note: The most significant bit is set if a digit is greater than or equal to 8.
Posted on 2008-10-07 18:14:03 by ti_mo_n
The Calculator with WindowsXP/2k/etc can do decimal-hex-bin conversions (F6,F5,F8 respectively). I use it to convert numbers around.
Posted on 2008-10-07 22:17:54 by Ultrano
Thanks, I wanted to know how to represent negative hex numbers so I could understand the basics of using loops in asm a little better, but I've found out about the 10,000 trick. thanks guys, you've helped a million
Posted on 2008-10-08 00:42:23 by angrynapkin