是什么在86定义字符串作为字节(DB)和定义字符串作为字/双字(DW / DD)之间的差异 [英] What is the difference between defining string as bytes (db) and defining strings as words/double words(dw/dd) in x86

查看:267
本文介绍了是什么在86定义字符串作为字节(DB)和定义字符串作为字/双字(DW / DD)之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调查组件限定标签之间的差异,这里是一个例子

  ALabel:DB'测试'
AAnotherLabel:DW'测试'

现在,让我这些加载到32位寄存器:

  MOV EAX,[ALabel]
MOV EBX,[AAnotherLabel]

在用gdb进行调查,我发现所有的EAX和EBX儿童寄存器包含相同的值,请看这里:

 信息EAX寄存器
0x64636261 // DCBA信息寄存器EBX
0x64636261 // DCBA

他们都是一样的!

在杰夫Duntemann的书(汇编语言一步一步编程Linux)的他显示字和双字到寄存器的一个例子,但由于某些原因加载偏移量(像这样的值的即地址)

  DoubleString:DD停止
MOV EDX,DoubleString

调查的EDX显示它包含一个地址,presumably字符串中的前四个字母的地址,并列只是第一次的地址,虽然我猜测这里的内容。

我想澄清什么是真正发生在这里,是这句话其实装载字符串中的第一个字母的地址到寄存器:

 翅:DB'最终'
MOV ECX,翅


解决方案

您在这里所说的2个不同的东西。

dB之间,DW,DD 结果差异
小丑给你已经正确的答案。下面是从NASM手册,这会帮助你理解它的两个例子。

当你用DW,存储在1个字(2字节)的步骤中创建。因此,它只能是2,4,6,8的尺寸...等等字节。在这个例子中,你有3个字节的abc的字符串。它只需要3个字节,而是因为你使用的德国之声这将是4个字节长。该4字节补0。

 翅:DW'ABC'; 0x61 0X62 0x63为0x00(串)

通过使用数据库,而不是DW,您可以创建存储在1个字节的步骤。这将是一个3字节长:

 翅:DB'ABC'; 0x61 0X62 0x63(串)

他们是所谓的伪指令,因为事实上,这是在你的汇编(在这种情况下NASM),告诉他如何分配你的存储命令。这不是一个code你的处理器阅读。来源:结果
3.2.1: http://www.nasm.us/doc/nasmdoc3.html

支架和没有括号结果
另一件事,你谈到了,是用括号[]与否。这又是什么它涉及NASM的语法。当你不使用括号,你告诉NASM的地址来工作。这将节省的内存地址在EAX:

  MOV EAX,鳍

这将挽救内存ADRESS前4个字节的EAX:

  MOV EAX,[鱼翅]

关于你的最后一个问题:

  DoubleString:DD停止
MOV EDX,DoubleString

DoubleString,内存地址,其中停止保存保存在EDX。每个地址对应一个字节。因此,地址 DoubleString 直接指向信'S'。地址 Doublestring + 1 指向下一个字节,其中字母'T'存储等。

来源:结果
2.2.2: http://www.nasm.us/doc/nasmdoc2 html的#部分-2.2.2

I'm trying to investigate the difference between defining labels in assembly, here's an example

ALabel: db 'Testing'
AAnotherLabel: dw 'Testing'

now, let me load these into a 32 bit register:

mov eax, [ALabel]
mov ebx, [AAnotherLabel]

upon investigation with gdb I found all of child registers of eax and ebx contain the same values, look here:

info register eax
0x64636261 //dcba

info register ebx
0x64636261 //dcba

They are the same!

In Jeff Duntemann's book (Assembly Language step-by-step programming with Linux) He shows an example of words and double words into registers, but for some reason loads the offset (ie the address of the value like so)

DoubleString: dd 'Stop'
mov edx, DoubleString

Investigation into the contents of edx show that it contains an address, presumably an address of the first four letters in the string, as apposed to the address of just the first, although I am speculating here.

I would like clarification of what is really happening here and is this statement in fact loading the address of the first letter in the string into a register:

Fin: db 'Final'
mov ecx, Fin

解决方案

You are talking about 2 different things here.

Difference between db, dw, dd
Jester gave you already the correct answer. Here are two examples from the NASM manual, which should help you to understand it.

When you use dw, storage is created in steps of 1 word (2 bytes). Thus it can only have the size of 2, 4, 6, 8... and so bytes. In this example you have a string of 3 Bytes 'abc'. It only needs 3 Bytes, but because you used 'dw' it will be 4 bytes long. The 4. byte is filled with 0.

fin: dw 'abc'               ; 0x61 0x62 0x63 0x00 (string)

By using db instead of dw, you can create storage in 1 byte steps. This one will be 3 bytes long:

fin: db 'abc'               ; 0x61 0x62 0x63 (string)

they are called pseudo-instructions, because actually, that are commands at your assembler (in this case NASM), which tells him how to allocate your storage. It is not a code your processor has to read. Source:
3.2.1: http://www.nasm.us/doc/nasmdoc3.html

Brackets and no brackets
The other thing, you talked about, is using brackets [] or not. That is again something which concerns NASM's syntax. when you use no brackets, you tell NASM to work with the address. This will save the memory address in eax:

mov eax, fin

This will save the first 4 bytes from the memory adress in eax:

mov eax, [fin]

About your last question:

DoubleString: dd 'Stop'
mov edx, DoubleString

DoubleString, the memory address, where 'Stop' is saved is saved in edx. Every address corresponds to one byte. Thus the address DoubleString points directly to the letter 'S'. The address Doublestring+1 points to the next byte, where the letter 't' is stored and so on.

Source:
2.2.2: http://www.nasm.us/doc/nasmdoc2.html#section-2.2.2

这篇关于是什么在86定义字符串作为字节(DB)和定义字符串作为字/双字(DW / DD)之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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