Home > front end >  confused about address of value in stack
confused about address of value in stack

Time:02-20

below is some working - 16 bit x86 assembly


        global    _start

        section   .text
_start: mov ah, 0x0e

        mov bp, 0x8000
        mov sp, bp

        push "A"
        push "B"
        push "C"

        pop bx
        mov al, bl
        int 0x10

        pop bx
        mov al, bl
        int 0x10

        mov al, [0x7ffe]
        int 0x10
        
        jmp $
        
        times 510 -( $ - $$ ) db 0
        dw 0 xaa55

I push 3 values onto the stack , and then print the first 2. I am attempting to print the third value by indirect adressing , hence mov al, [0x7ffe] - but question Is , because the stack has a base of 0x8000 and can only pop 16 bit values , wouldn't the address of the last character to be printed,- "a" be 0x8000 - 0x1 = 0x7FFF rather than 0x8000 - 0x2 , which is 0x7FFe as adressed in the code above , as 1 16-bit byte is 0x10?

CodePudding user response:

In x86 real mode you cannot push an 8-bit value. Therefore your three push instructions are actually pushing the 16-bit values 0x0041, 0x0042, and 0x0043. Since x86 is little-endian, the actual character part of the value comes "first", so the 0x41 representing "A" will be located at address 0x7ffe.

  • Related