A
A
Andr2016-11-13 15:20:19
assembler
Andr, 2016-11-13 15:20:19

Assembler how to solve the problem?

Hello! I ask for help in the following question: I study assembler in college. A new teacher has arrived. Azov did not give. He explained what commands there are, but did not say how to apply.
I have given this task. If a person enters a number from 0 to 9, then if greater than, equal to, and less than 5, a message was displayed.
She said that there are no teams less, equally. And everything needs to be done through the cmp command
I had an idea. I told the program, if less than 5, then the message is.
For example:
sgt segment
org 100h
begin:
mov ah, 1h
int 21h
cmp al, 5
cmp 0.5
jz OK_1
_________
OK_1:
mov ah, 9h
mov bx, offset mes1
mes1 db 'Menshe'
jmp segment
And so with all numbers from 0 to 9.
Did I do everything right?
Can you tell me the best way to write a program?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2016-11-13
@15432

The comparison really happens via cmp , but a further jump ( jmp ) can be made under several conditions. The cmp command performs a normal subtraction, and sets flags according to the result. Among the flags there are, for example, ZF - Zero Flag, set if the result is zero, that is, the compared numbers were equal. You just used the command jz - J ump if Z ero (jump if zero), which checks exactly this flag.
For "less than or equal" comparisons, use the jle command ( J ump if L ess or Equal), the transition to the address specified in it will occur only if the first number in the comparison was less than or equal to the second.
Other jump command options are listed here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question