This discussion is closed.
Unregistered
Badges:
#1
Report 16 years ago
#1
Hey, I've been doing some past exam questiosn to aid my revision, and i'm not sure about one question.

Here is the question:

Write the sequence of key assembly language instructions, with annotations, which correspond to the following block of high level language code. (5)

x <-- 0;
WHILE x < 10
DO x <-- x+1;
ENDWHILE

The answer i got is as follows:

LDA #0 - load 0 into the accumulator.
MOV A,X - move contents of accumulator into register x.
LDA #10 - load 10 into the accumulator.
MOV A,R1 - move contents of accumulator into register 1.
CMP X,R1 - compare contents of register x with register 1.
BRG E - branch to E if register x is greater than register 1.
B ADD #1,X - add 1 to register x.
CMP X,R1 - compare contents of register x with register 1.
BRG B - branch to B if register x is less than register 1.
E

If anyone could tell me if this would get the marks I would be grateful.
0
Flakker
Badges: 0
#2
Report 16 years ago
#2
Im not sure about your code, but I would use something like the following:


LDA #0 'put 0 in accumulator
STA x 'store accumulator value in x
While: LDA x 'put x value into accumulator
ADD 1 'add 1 of course
STA x 'put accumulator value in x
CMP x, #9 'compare x and 9
JNZ while 'jump to "while" unless x=9
Exit: ?..

Hope that helps!
Chris
0
X
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Regarding Ofqual's most recent update, do you think you will be given a fair grade this summer?

Yes (267)
34.27%
No (512)
65.73%

Watched Threads

View All