Page 1 of 1

Reading defined bytes that i loaded into a different segment

Posted: Sun Nov 29, 2020 10:28 pm
by astralorchid
[NASM, real mode]

I loaded this code off of the disk at 0x1000:0x0000

Here is the memory address of "wtf" being pushed onto the stack in segment 0x1000, then returning to segment 0:
(i pop it in segment 0, then print the value on screen)

Code: Select all

mov ax, wtf
push ax
push ds

mov ax, 0
push ax
mov ax, word [ds:0x1000]
push ax
retf ;going back to segment 0

wtf db 'hi', 0
and here is me trying to access the memory address from segment 0

Code: Select all

mov ax, 0x1000
mov ds, ax

mov ah, 0x0e
mov al, byte [ds:0x004e]
int 0x10
im using 0x004e because that is the value that got pushed onto the stack with "push wtf". However, int 0x10 outputs null and still moves the cursor. The expected output would be 'h'... What is going on here?

Re: Reading defined bytes that i loaded into a different seg

Posted: Mon Nov 30, 2020 7:54 pm
by Octocontrabass
I don't think you've provided enough information to say what's going on. Perhaps you should use a debugger to see if the values in memory match up to your expectations.

Why do you need to use different segments?

Re: Reading defined bytes that i loaded into a different seg

Posted: Tue Dec 01, 2020 11:09 am
by PeterX
Your code looks unneccessarily complicated. May I ask what you are trying to do with that code?

Greetings
Peter