Assembly Language - LDI

一个人想着一个人 提交于 2020-01-25 07:35:12

问题


I am having trouble figuring out weather to load a regisiter with the contents of the data in the regisiter or indirectly load the register with the address of the value when we execute LDI.

Example:

x3000 LDI R6, far
x3001 ...(some command)
x3002 ...(some command)
x3003 far x6000
...
x6000  xf000

what is the data in R6 after excecuting x3000?


回答1:


well take this for example

.orig x3000
LDI R6, far
ADD R0,R0,#0
ADD R0,R0,#0
far .fill x6000
.end

assemble and dump

hexdump -C test.obj
00000000  30 00 ac 02 10 20 10 20  60 00                    |0.... . `.|
0000000a

and hand disassemble

0x3000: 0xAC02  ldi r6,#+2 
0x3001: 0x1020  add r0,r0,#0
0x3002: 0x1020  add r0,r0,#0
0x3003: 0x6000  

The LDI instruction does this:

DR = mem[mem[PC† + SEXT(PCoffset9)]];
setcc();

the lower 9 bits of the instruction are 0x002 which sign extends to be 0x0002. the pc is the modified pc so when executing the instruction at address 0x3000 the pc is actually 0x3001 so

DR = mem[mem[0x3001+0x0002]]
DR = mem[mem[0x3003]]
DR = mem[0x6000]
DR = 0xF000 using your definition for what lives at address x6000.
DR is r6 so 0xF000 is stored in r6.  
0xF000 is considered a negative so the flags are N = 1, Z = 0, P = 0 if I understand the flags correctly.


来源:https://stackoverflow.com/questions/14843084/assembly-language-ldi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!