这在汇编中起什么作用
我的老师希望我们对汇编有一个基本的了解,因为以后这可能会有所帮助。我对此很满意,但除了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了回答您对移位的疑问,它所做的是将所有位向左移动一位,并添加零作为第一位。换句话说,它将变量
varclist
的高值(或低值)乘以 2。程序中的
varclist
是内存中字节数组 [ 0x01, 0x02, ... 0x00 ] 的地址 =>varclist
是指向该数组第一个字节的指针。要获得原始地址,我们只需除以 2(乘法的逆运算)即可获得所以
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 obtainSo the
varclist
address was0x0038
. 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
r0
thanks to theLPM
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.