本文介绍了定义“变量".用汇编语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我理解这是非常愚蠢的问题,但一段时间以来我都找不到答案
如何在GAS AT& T汇编语言中正确声明和定义变量"?
例如,我要缓冲5个字节,两个1个字节的变量(初始值为0),2个字节的变量0和2个字节的变量10.
这段代码无法正常工作,至少调试器说(在程序的第一行,在这些声明之后,只是nop指令)bc是大数字而不是零.

I underdstand that this is extremely stupid quiestion, but I can't figure an answer for some time
How do I correctly declare and define "variables" in GAS AT&T assembly language?
For example, I want buffer for 5 bytes, two 1-byte variables (initially with 0 value), 2-byte variable with 0 and 2-byte variable with 10.
This code doesn't work correctly, at least debugger says (on the first line of the program, after these declarations, just nop instruction) that b and c are big numbers instead of zeros.

.bss
    .lcomm r, 5

.data
    a:  .byte 0
    b:  .byte 0
    c:  .word 0
    d:  .word 10

推荐答案

这是您在手表"窗口中看到的内容:

Here's what you see in your "Watches" window:

a = 0 = 0x00 = 0x0000 = 0x00 0000 = 0x0000 0000

b = 167772160 = 16777216 * 10 = 0x1000000 * 0x0A = 0xA000000

c = 655360 = 65536 * 10 = 0x10000 * 0x0A = 0xA0000

d = 10 = 0x0A = 0x0000 000A

是什么意思?这意味着您的编译器完成了工作,但是调试器将cb读取为双字(4个字节)而不是字节.

What does it mean? It means that your compiler did its job, but your debugger reads c and b as doublewords (4 bytes) instead of bytes.

在读取b时,将在顶部读取其值0x00c的值0x0000d的值0x0A,一起使其成为0xA000000.

When it reads in b, it reads its value 0x00, c´s value 0x0000, and d´s value 0x0A on the top, together making it 0xA000000.

c发生类似的情况. a很幸运,因为接下来的4个字节为零,所以a实际上为零.

Similar thing happens to c. a got lucky, as the next 4 bytes are zero, so the a is really zero.

但是,并非总是如此.没什么说d之后不能有任何垃圾,更不用说等于.bss中(在完全不同的内存位置上).

However, this doesn't always have to be the case. Nothing says that there can't be any garbage after d, not to mention that variables equal to zero may appear in .bss (on a completely different memory location).

这篇关于定义“变量".用汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 03:08