这在汇编中起什么作用

发布于 2024-12-27 15:52:40 字数 472 浏览 0 评论 0原文

我的老师希望我们对汇编有一个基本的了解,因为以后这可能会有所帮助。我对此很满意,但除了 4 个小例子外,我的大学提供的有关该主题的文档为零。我试图弄清楚这其中发生了什么:

.DEVICE ATmega32

.CSEG
main:

ldi    ZL,low(varclist<<1)
ldi    ZH,high(varclist<<1)

.CSEG
varclist:
.db    1, 2
.db    3, 4
.db    5, 6
.db    7, 8
.db    9, 0

我正在 AVR studio 5 中工作,并查看“处理器”选项卡。我似乎找不到“varclist”中的值与寄存器显示的十六进制值之间的任何关系。我怎么看这个?

我希望 Z 寄存器包含 0x0100,因为我想象“最高有效”位是第一个声明的,而最低有效位是最后声明的。不过,我看到的是 0x0070。不过,我不确定转变会做什么。

My teacher wants us to have a basic understanding of assembly, because later down the road, that might be helpful. I'm fine with that, but my college provides zero documentation on the subject, apart from 4 small examples. I'm trying to figure out what is happening in this one:

.DEVICE ATmega32

.CSEG
main:

ldi    ZL,low(varclist<<1)
ldi    ZH,high(varclist<<1)

.CSEG
varclist:
.db    1, 2
.db    3, 4
.db    5, 6
.db    7, 8
.db    9, 0

I'm am working in AVR studio 5, and looking at the 'processor' tab. I can't seem to find any relation between the values in 'varclist', and the hexadecimal values the registers are showing. How do i look at this?

I would expect the Z register to contain 0x0100 as i would imagine the 'most-significant' bit to be the first one declared, and the least significant the last declared. I'm seeing 0x0070, however. I'm not sure what the shifting does, though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恬淡成诗 2025-01-03 15:52:40

为了回答您对移位的疑问,它所做的是将所有位向左移动一位,并添加零作为第一位。换句话说,它将变量 varclist 的高值(或低值)乘以 2。

程序中的 varclist 是内存中字节数组 [ 0x01, 0x02, ... 0x00 ] 的地址 => varclist 是指向该数组第一个字节的指针。要获得原始地址,我们只需除以 2(乘法的逆运算)即可获得

0x0070 >> 1 = 0000 0000 0111 0000 >> 1 = 0000 0000 0011 1000 = 0x0038

所以 varclist 地址为 0x0038。我不知道你怎么认为这是 0x0100,但我希望你现在能理解这段代码。

我认为这个地址要乘以 2,因为程序存储空间的地址以字偏移量表示,在这种情况下,您需要乘以 2 才能获得字节偏移量中的地址。稍后,借助 LPM 汇编指令,您可以将该字节(数组的第一个字节)加载到 r0 中。

我建议您阅读此 pdf 的第 5.2 章以及可能的其他章节出色地。 AVR 汇编器用户指南 也可能是一个不错的选择。

To answer your wondering about the shifting, what it does is shift all the bits by one to the left adding a zero as first bit. In other words it multiplies by 2 the high (resp. low) value of the variable varclist.

varclist here in your program is the address of the array of bytes [ 0x01, 0x02, ... 0x00 ] in memory => varclist is a pointer to the first byte of this array. To obtain the original address, we just need to divide by 2 (reverse operation of the multiply) and we obtain

0x0070 >> 1 = 0000 0000 0111 0000 >> 1 = 0000 0000 0011 1000 = 0x0038

So the varclist address was 0x0038. I don't know how you thought this was 0x0100 but I hope you now understand the code.

I think this address is multiplied by 2 because addresses to the program storage space are expressed in word offset, in which case you'll need to multiply by 2 to get the address in a byte offset. Later you can load that byte (the first byte of your array) into r0thanks to the LPM assembly instruction.

I would recommend you read the chapter 5.2 of this pdf and possibly the other chapters as well. The AVR Assembler User Guide is also probably a good bet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文