0

when i run this code then success is always called even when i enter other characters like v.

global start
section .text
start:
    mov ax, 07C0h       ; Set up 4K stack space after this bootloader
    add ax, 288     ; (4096 + 512) / 16 bytes per paragraph
    mov ss, ax
    mov sp, 4096

    mov ax, 07C0h       ; Set data segment to where we're loaded
    mov ds, ax
   

    call read_key
    call display
    
    cmp al, 'm'
    je success

    cmp al, 'M'
    je success
    

success:
    mov al, 'C'
    call display


read_key:
    push bx
    push cx
    push dx
    push si
    push di
    mov ah, 0x00
    int 0x16
    pop di
    pop si
    pop dx
    pop cx
    pop bx
    ret
display:
    push bx
    push cx
    push dx
    push si
    push di
    movzx si, al
    mov ah, 0Eh
    int 10h
    pop di
    pop si
    pop dx
    pop cx
    pop bx
    ret
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
dent
  • 1
  • 1
  • 1
    What other did you expect? After `je success`the code falls through to `success`label. You nedd a goto instruction or an other branch. – Mike May 02 '22 at 08:41
  • so how to make that success is not executed by itself – dent May 02 '22 at 08:43
  • Jump somewhere else if it's not `'M'`, instead of falling through into `success:`, as in [How to use jumps in assembly language?](https://stackoverflow.com/q/72061257) and [Code executes condition wrong?](https://stackoverflow.com/q/32872539) – Peter Cordes May 02 '22 at 08:44

1 Answers1

0

If al is neither 'm' nor 'M', then the program counter would go down without branching to success. What do you see down there, success: