0

I'm learning assembly and I'm fairly new to it. I'm doing a basic sum program and when it's done, I have a prompt to ask if I would like to "continue: y/n". When I call readChar(stores in AL register), and call a JE(jump equal) command, nothing happens. It doesn't seem like it's recording the character input into the register. It doesn't jump to my "L2" label and continues on line by line. Any idea why?

INCLUDE Irvine32.inc

.data
firstPrompt BYTE "Enter first 16 bit unsigned integer: ", 0
secondPrompt BYTE "Enter second 16 bit unsigned integer: ", 0
reenterPrompt BYTE "The number must be between 0 and 65,535 ", 0
continuePrompt BYTE "Continue: y/n:", 0
sumPrompt BYTE "Sum = ", 0
arr BYTE 5 DUP (?), 0

.code
main PROC  

L1:
     mov edx, OFFSET firstPrompt
     call writeString
     call readInt
     cmp eax, 0
     jl falseCase
     cmp eax, 65535
     ja falseCase
     mov bx, ax ;bx = first int
L2:
     mov edx, OFFSET secondPrompt
     call writeString
     call readDec ;ax = second int
     cmp ebx, 65535 
     jl falseCase
     cmp bx, 0
     jae trueCase
trueCase: ;if true, sum both intergers, print the sum and prompt to continue
     add ax, bx
     mov edx, OFFSET sumPrompt
     call writeString
     call writeDec
     call crlf
     mov edx, OFFSET continuePrompt
     call writeString
     call readChar
     cmp al, 'y'
     or al, 'Y'
     call crlf
     je L2
falseCase:
     mov edx, OFFSET reenterPrompt
     call writeString
     call crlf
     jmp L1
CJay
  • 1
  • 5
  • Does your `crlf` function clobber the compare result in EFLAGS? I think Irvine32 preserves all integer registers, but I'm not sure about flags. Anyway, `cmp al, 'y'` / `je` *after* the last `call`. **Use a debugger to look at EFLAGS while you single step**. – Peter Cordes Mar 06 '19 at 05:43
  • I don't think so, I removed the crlf call just in case and it's still the same thing. I provided my whole code. – CJay Mar 06 '19 at 06:14
  • But you didn't take out the `or al, 'Y'` that's clobbering the flag-result of `cmp`? `or` is a bitwise OR operation that sets ZF according to the result being zero or not. Perhaps you want `or al, 0x20` to force lowercase (if it was `Y`), then `cmp al, 'y'` . See [What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?](//stackoverflow.com/a/54585515) – Peter Cordes Mar 06 '19 at 06:36

1 Answers1

0

or is a bitwise OR operation that sets ZF according to the result being zero or not. It's clobbering the flag-result of cmp before you read it with je

I think you're trying to check if al is 'y' or 'Y'. Since those values differ only in one bit position, you can check both by ignoring that bit (unconditionally setting or clearing it).

e.g. or al, 0x20 to force lowercase (if it was Y), then cmp al, 'y' to set FLAGS according to al - 'y' (i.e. set ZF if they were equal).

See What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847