汇编中的变量地址 [英] Variables address in Assembly

查看:134
本文介绍了汇编中的变量地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我回到了Assembly,但是我无法使用变量解决问题. 我写了超级简单的程序,我不知道为什么它不起作用.

I comeback to Assembly and I can't resolve my problem with variables. I wrote super simple program and I can't figure why it doesn't work.

msg db 'a'
mov ah, 0Eh
mov al, [msg]
int 10h

我将其编译为.com文件,并在DOS中使用debug命令检查正在发生的事情,然后看到类似的内容

I compile it into .com file and I use debug command in DOS to check what's going on and I see something like this

119A:0100 61     DB 61
119A:0101 B40E   MOV AH, 0E
119A:0103 A00000 MOV AL, [0000]
119A:0106 CD10   INT 10H

我的问题是,当变量位于0100上时,为什么0000地址变量进入了AL?我尝试使用org指令并设置ds register,但是它不起作用.而且请不要说我必须使用段,因为我正在编写没有NASM内容的引导加载程序,并且我试图了解如何解决wokrs.

My question is why 0000 address variable going to the AL when my variable is on the 0100? I tried to use org instruction and setting ds register but it doesn't work. And please don't say that I have to use segments becasue I'm writing a bootloader without this NASM stuff and I try to understand how addressing wokrs.

推荐答案

我将其编译为 .com 文件

我正在编写 bootloader

这两个人相处得不好! .COM文件格式(需要ORG 100h指令)是DOS的东西,但是由于您正在编写引导加载程序,因此不会有任何DOS来执行程序.

These two don't go together well! The .COM file format (requiring the ORG 100h directive) is a DOS thing, but since you're writing a bootloader there won't be any DOS to execute your program.

您的Bootloader程序将由BIOS加载到内存中,并且需要从顶部开始执行.当然,这意味着在第一个偏移地址上必须有可执行指令,而不是像当前程序中那样的静态数据.

Your bootloader program will be loaded to memory by BIOS and the execution needs to start from the top. Of course this mean that at that first offset address there must be executable instructions and not the static data like in your current program.

一种解决方案是跳过这些数据:

One solution is to jump over this data:

jmps MyStart    ; EB 01     'jmp short'
msg  db 'a'     ; 61
MyStart:
mov  ah, 0Eh    ; B4 0E
mov  al, [msg]  ; A0 02 00  <-- offset is 0002h
int  10h        ; CD 10

为了正确设置DS,您可以编写:

In order to setup DS correctly you can write:

ORG  7C00h
jmps MyStart    ; EB 01     'jmp short'
msg  db 'a'     ; 61
MyStart:
xor  ax, ax     ; 30 C0
mov  ds, ax     ; 8E D8
mov  ah, 0Eh    ; B4 0E
mov  al, [msg]  ; A0 02 7C  <-- offset is 7C02h  
int  10h        ; CD 10

ORG 7C00h是您向汇编程序的承诺,该程序将以7C00h的偏移地址加载到内存中.

ORG 7C00h is your promess to the assembler that this program will be loaded in memory at an offset address of 7C00h.

因为BIOS将其加载到线性地址0000:7C00h,所以将DS段寄存器设置为零是完成此特定ORG的正确方法.

Because BIOS loads it at linear address 0000:7C00h, setting the DS segment register to zero is the correct way to complete this particular ORG.

这篇关于汇编中的变量地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆