Discussion Locked

Programming in assembler

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am required to take an input from a user - a four digit code, store it in a register and then compare against a pre-stored value (stored in another register, another four digit code). I am a complete assembler novice and so need help with this.

10 replies

by epepke

You haven't given many details. What assembler? What processor? What environment?

WRT your project, though, by far the most difficult part is going to be taking the input from the user. Everything else is trivial. With a four-digit code, theeasiest thing to do is to pack it into a 32-bit word and use some sort of comparison (depending on the assembler and your preference: cmp, xor, or sub) and then do a conditional jump based on what is in the flags register. A handful of instructionsat the most. Some processors have instructions to do packing of BCD easily; some you will have to dink with using shift instructions. In any event, it's simple, conceptually like this:

Start with rWhatever = 0;
For each of four input digits Shift rWhatever left 8 bits
Or it with the input digit

At the end, rWhatever is the BCD expression. Then just do a comparison to the other register holding the check code, similarly built up.

by ms_saini3302

you can stroe input number in a array and then you can compare one by one digit with pre stroe digits. First try it your self.

This discussion is closed to new replies.