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?

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?

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 !!!

:)

FFF6, if you think about it, is actually -10 !!! MINUS TEN !!!

:)

Thanks for confirming my suspicions, I was wondering if something like that was the deal. Thank you!

The asm code is perfect.

"while(X<10)" means "while(X-10<0)".

"while(X<10)" means "while(X-10<0)".

Yeah. It's just, interesting going from high level language to machine and assembly.

Can anyone point me towards a primer with 2's complement using hex numbers? I've done it with binary.

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.

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.

The Calculator with WindowsXP/2k/etc can do decimal-hex-bin conversions (F6,F5,F8 respectively). I use it to convert numbers around.

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