• 1

Convert from Pseudo-code to assembly instructions


Question

Hi there, I've got this homework problem I'm stuck with, I've got a few questions so I'm not asking for help on all of them, but if someone could help me out with this first one it'll show me the direction to complete the others.

I have to take small sections of high-level pseudo-code and convert it into assembly instructions, (obviously not majorly specific but to get a general idea of the instructions that would be used).

Currently struggling on BRANCHES used as a replacement for IFs and LOOPs. If someone could do this question, I'd be really grateful, thanks.

A <-- 0;
Repeat
     A <-- A + 1;
Until A = 99; 

For example, I know "A <-- A + 1" would be something like "INC A" for increment.

Many thanks in advance.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

In x86 Assebly assuming ax is variable a:

mov ax, 0     &lt;--- Set ax to be 0
repeat: inc ax   &lt;---- ax = ax + 1
cmp ax, 99         }
jne repeat          } loop while ax != 99 (same as loop until ax = 99)

Link to comment
Share on other sites

  • 0

sorry i wont do the question for you, however i will give you a little help, basicly what you need to to is move 0 in to ax register, then put a label on the line with the increment ax instruction, compare register a with 99, then do a branch if not equal (BNE) to the label.

guess im a little slow at typing

Link to comment
Share on other sites

  • 0
I see - many thanks - what does the "xor ax, ax" mean?

585024631[/snapback]

It's a habit with x86 programmers. It effectively clears ax (sets it to zero). It's usuallu done this way since it saves one byte of caode (yes, one precious byte). :p

EDIT: Damn it! I didn't read the HW part. I shouldn't have given you the answer. But is you're not using x86 (it's not taught in uni since it's crap), then it's not much help.

Link to comment
Share on other sites

  • 0

The whole point is that I've got tons of these questions, so someone doing one for me as an example is only gonna help me - I was v. specific about that in my first post.

Thanks v. much for the help :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.