OK, before someone else marks this question as a duplicate. Let me make this very clear that this is more of a debugging problem than a logical problem. The logic is correct as far as I know because if I individually print the value in bx register after each operation, then I get correct output. The problem is that storing the results in bx register should make changes in the memory location it holds which is not happening.
So, I was learning assembly language these days, in NASM. I am following a pdf document which asks you to print a hexadecimal number (convert hex number to hex string and then print it).
I've written the code but it doesn't seem to print the correct hex number. On the other hand if I just print the variable FINAL_ST in the following code snippet without calling INIT (which is the start of the conversion of hex number to hex string), it works fine and prints 0x0000.
I've searched multiple times but to no avail.
I found out that gdb can be used to debug nasm programs but I could not understand how to use it when the output is a .bin file.
And I also tried constructing a Control Flow Graph for this code to understand execution flow but could not find an appropriate tool for it. :(
Code:
[org 0x7c00]
mov ax, 0x19d4
mov bx, FINAL_ST + 5
; jmp PRINTER ; works :/
jmp INIT
NUM:
    add dx, 0x0030
    mov [bx], dx
    jmp CONT
ALPHA:
    add dx, 0x0037
    mov [bx], dx
    jmp CONT
CONT:
    dec bx
    shr ax, 4
    cmp ax, 0x0000
    jne INIT
    je PRINTER
INIT:
    mov dx, 0x000f
    and dx, ax
    cmp dx, 0x000a
    jl NUM
    jge ALPHA       
;STRING PRINTER
PRINTER:
    mov bx, FINAL_ST
    mov ah, 0x0e
    jmp PRINT ; this doesn't work
PRINT:
    mov al, [bx]
    int 0x10
    inc bx
    cmp byte[bx], 0x00
    jne PRINT
FINAL_ST:
    db "0x0000", 0x00  
END:
times 510 - ($ - $$) db 0
dw 0xaa55
Commands used:
nasm boot_hex1.asm -f bin -o boot_hex1.bin
qemu-system-x86_64 boot_hex1.bin
I get the output as 0x1 while the expected output is 0x19D4.
 
     
    