Reading defined bytes that i loaded into a different segment

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
astralorchid
Posts: 6
Joined: Sun Nov 29, 2020 10:24 pm

Reading defined bytes that i loaded into a different segment

Post 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?
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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?
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

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

Post by PeterX »

Your code looks unneccessarily complicated. May I ask what you are trying to do with that code?

Greetings
Peter
Post Reply