简体   繁体   English

间接寻址如何在汇编语言中使用Motorola 68k

[英]how does indirect addressing work in assembly language motorola 68k

I have this code: 我有以下代码:

loop2
        move.b  (a4)+,d3      * moving the morse code array input to d3
        muls    #5,d3
        add.b   $d3(a6),d3    * moving the character in morse code array to d4
        move.b  d3,d4
        cmp.b   #dot,d4

Here, I am accessing an array starting at a4 . 在这里,我正在访问从a4开始的数组。 I am taking an element of the array and multiplying it with 5 to move to the memory location where I have the desired element. 我正在获取数组的一个元素,并将其乘以5,以移至具有所需元素的内存位置。

a6 represents the starting point of an array which contains certain character. a6表示包含某些字符的数组的起点。

the statement $d3(a6),d3 wokrs but the code gets faulty as i know the code d3(a6),d3 should be correct but it show me an error. 语句$d3(a6),d3起作用,但是代码出错,因为我知道代码d3(a6),d3应该是正确的,但显示出错误。 how should i do it ? 我该怎么办?

What's happening is since $ is for specifying hex constants, and d3 is technically a valid hex constant, it's using a6 + 0xd3 as the memory address. 这是因为$是用于指定十六进制常量,而d3从技术上讲是一个有效的十六进制常量,它使用a6 + 0xd3作为内存地址。 What you're trying to accomplish uses different syntax, namely both registers are in the parentheses: (a6,d3) 您要完成的操作使用了不同的语法,即两个寄存器都在括号中: (a6,d3)

So the correct statement is: 因此正确的陈述是:

add.b   (a6,d3),d3

In add.b (a6,d3),d3 you probably should declare size of d3 used for address generation: either (a6,d3.w) or (a6,d3.l) , depending on what you need. add.b (a6,d3),d3您可能应该声明用于地址生成的d3的大小: (a6,d3.w)(a6,d3.l) ,具体取决于您的需求。 In general case, after a multiplication you have full 32bit result and should use d3.l . 通常,在乘法之后,您具有完整的32位结果,应使用d3.l Only if you are sure that the result of multiplication fits 16bit you can use d3.w . 仅当确定乘法结果适合16位时,才可以使用d3.w
If you write code specifically for 68020+ (020,030,040,060), also consider using scaled addressing mode like (a6,d3.w*n) , where n is one of 1, 2, 4, 8. 如果您专门为68020+(020,030,040,060)编写代码,还可以考虑使用诸如(a6,d3.w*n)类的缩放寻址模式,其中n是1、2、4、8之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM