0

I'm currently learning about AT&T Assembly, and i'm having a problem with conditional jump. Here's what i'm doing

.section .data
msg_less:
    .string "Less than 65"
msg_greaterequal:
    .string "Greater than or equal to 65"
.section .bss:
    .lcomm input, 2
.section .text
    .globl _start

_start:
    #Input a char
    movl $3, %eax
    movl $0, %ebx
    movl $input, %ecx
    movl $2, %edx
    int $0x80

    #Output the previous char
    subl $1, (input)
    movl $4, %eax
    movl $1, %ebx
    movl $input, %ecx
    movl $2, %edx
    int $0x80

    #Check if the numeric value of the input char is less / greater than or equal to 65 
    #If input < 65
    cmpl $65, (input)
    jl .L_less
    #Else: input >= 65
    movl $4, %eax
    movl $1, %ebx
    movl $msg_greaterequal, %ecx
    movl $28, %edx
    int $0x80
    jmp .L_End

.L_less:
    movl $4, %eax
    movl $1, %ebx
    movl $msg_less, %ecx
    movl $13, %edx
    int $0x80
#End
.L_End:
    movl $1, %eax
    int $0x80

The "Input" and "Print previous char" worked correctly, but the "Check if" always jumps to "Greater than or equal to 65" case regardless of the input

Screenshot of result while running

And if i change jl to jge the result will always jump to "Less than 65" case. I don't know what caused this, and how to fix this?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Phat Tran
  • 65
  • 3
  • 2
    `cmpl $65, (input)` is a 4-byte compare, of 4 bytes including the newline you read, as well as 2 bytes past the end of the space you reserved in the BSS (which are probably zero). Use `cmpb` if you want to compare a byte. – Peter Cordes Apr 07 '21 at 04:48
  • General advice: do not develop software as root unless you know exactly what you are doing. This is fairly dangerous to do. – fuz Apr 07 '21 at 10:39

0 Answers0