0

When I run this code then the variable ms2 is printed two times even thought I called it for once only. There are two files boot.asm and display.asm and boot.asm is my main file. boot.asm -

global start
section .data
ms1 db " You have successfully loged in", 13, 10
ms2 db "---------------------------------------------", 13, 10
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"
    jne failure

success:
    jmp success_deal
failure:
    jmp failur_deal
success_deal:
    
    

    mov si, ms1
    mov bl, 2
    call print_string
    pop si

    mov si, ms2
    mov bl, 2
    call print_string
    pop si



    %include "display.asm"

    

failur_deal:
    call new_line
    mov al, " "
    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
new_line:
    push bx
    push cx
    push dx
    push si
    push di
    mov dl, 10
    mov ah, 2
    int 21h
    mov dl, 13
    mov ah, 2
    int 21h
    pop di
    pop si
    pop dx
    pop cx
    pop bx
    ret

display.asm-

print_string:
    mov ah, 0Eh
    cmp bl, 3       ; int 10h 'print char' function
    jne .repeat
    ret


.repeat:
    lodsb           ; Get character from string
    cmp al, 0
    je .done        ; If char is zero, end of string
    int 10h         ; Otherwise, print it
    jmp .repeat

.done:
    ret
    times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55 
    mov bl, 3
    pop si

The output I get is - Output

Please help so that I get it printed just once.

dent
  • 1
  • 1
  • The reason is probably that you don't have an ending so you fall through into the printing code again. You should put something like an endless loop at the end of `success_deal` and `failur_deal` – Jester May 05 '22 at 13:14
  • Yes that should be fine. – Jester May 05 '22 at 13:23
  • Duplicate of [Is there a relevance for where you place %include directive in NASM code?](https://stackoverflow.com/q/19739915) but IIRC there are more exact duplicates about putting a `%include` where execution will fall into it. Ah, found one: [Assembly with %include at the top - Printing Outputs Unexpected Result: just an " S"](https://stackoverflow.com/q/61072003) – Peter Cordes May 05 '22 at 14:41

0 Answers0