I'm allowed to use the C functions printf, scanf, and puts. I get a number from the user (which is easy), but I need to check to see if it's less than 0 or greater than 255? I know how to compare single digit numbers but am stuck on how to compare negative or numbers >9. would cmp eax, 0 and cmp eax,255 work?
Asked
Active
Viewed 2,307 times
-2
-
Use scanf to get the input into a number (rather than a text representation of one). From there, just use the appropriate jmp after the comparison instructions. For some, the comparison is signed, for others, not. – enhzflep Oct 26 '14 at 15:43
-
The problem is a little bit unclear. Didn't you convert the (ASCII-)input to a register value e.g. with `scanf`? Please add code that shows the problem. – rkhb Oct 26 '14 at 15:44
1 Answers
1
It will do what you intend just
whith cmp eax,0
instead of jb
you should
use jl
(Jump if first operand is Less) cause it will be signed comparison

qwr
- 3,660
- 17
- 29