Search code examples
assemblyasciix86-16emu8086

Problem with assembly (emu8086): It doesn't print the right value


When I compile and execute the code with emu8086, it doesn't print the right value. Rather it prints the value 0. I don't understand why. Can someone please explain this to me?

This is the code:

    format MZ   

entry code_seg:start ; set entry point

stack 256  

segment data_seg

     
     VAR1 DB 5     

    
segment code_seg
start:
; set segment registers:
    mov ax, data_seg
    mov ds, ax


    
    ;print the value
    MOV AH,02H
    MOV DL,VAR1       
    ADD DL,30H
    INT 21H
    
    ; wait for any key....    
    mov ah, 1
    int 21h
    
    mov ax, 4c00h ; exit to operating system.
    int 21h    

Solution

  • in Data segment you need to append h after value so your data segment should be like these.

    VAR1 DB 05h