Loading 16-bit Numbers into D and X Registers

  • Thread starter Thread starter EvLer
  • Start date Start date
  • Tags Tags
    Numbers
Click For Summary

Discussion Overview

The discussion revolves around loading two 16-bit numbers from memory into the D and X registers in assembly language, specifically for the 68HC12 microcontroller. Participants explore the use of the FDIV instruction for division and address the challenges of loading data correctly into the registers.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant questions how to load two separate 16-bit numbers into the D and X registers, noting that the rmb directive reserves 4 bytes for two 16-bit numbers but is unsure how to load them correctly.
  • Another participant requests references to assembly language documentation, indicating a need for additional resources.
  • A later reply suggests a solution involving loading the Y-register with the address of "ops" and using indexed addressing mode with an offset to load the second number, indicating a successful modification of the original code.
  • A follow-up question is raised about whether variables in assembly can be set directly like in high-level languages or if they must always go through registers.
  • Another participant asserts that it is possible to set variables directly, suggesting that the original poster should look further for clarification.
  • A question is posed regarding the use of co-processor registers versus main registers in the context of the 68HC12 architecture.
  • The original poster confirms their assumption about using only the main registers available in the 68HC12.

Areas of Agreement / Disagreement

Participants express uncertainty about the best method for loading data into registers and whether direct variable assignment is possible in assembly. There are multiple competing views on the use of registers and addressing modes, and the discussion remains unresolved regarding the optimal approach.

Contextual Notes

Participants discuss the limitations of assembly language in terms of variable assignment and register usage, but do not resolve the specifics of these limitations or the implications for coding practices.

EvLer
Messages
454
Reaction score
0
I need to read-in two 16-bit numbers from memory and divide one by the other. Well, i think i need to use FDIV instruction which would divide what's in D-register by what's in X-register, but i am stumped when it comes loading the data. Here's code we were given (commented is my solution)

Code:
        org     0800h
        ;ldd    ops
        ;ldx    ops (?)
        ;fdiv
        ;std    remain
        ;stx    quot
        stop   

ops      rmb     4
quot     rmb     2
remain  rmb     2
what bothers me is that rmb (reserve memory byte) is 4 which makes sense for 2 16-bit numbers but how do i load 2 separate 16-bit registers, so that first 2-bytes are loaded into D and second 2-bytes go into X?
D register will load 16 bits fine, but wouldn't X be loaded with the same 2 bytes? Technically i can figure out the address and load X with that address, but is there a "cleaner" way to do it?
thanks.
 
Physics news on Phys.org
Beats me. Can you provide pointers to the Assy language references please?
 
berkeman said:
Beats me. Can you provide pointers to the Assy language references please?
ummm... if you mean "references" it's CPU12 reference guide from freescale, http://www.freescale.com/webapp/sps...ce=68HC912B32&DocTypeKey=10Ksfwlk&Results=25"
but i think i got it last night: i loaded Y-register with the address of the "ops" and then used indexed addressing mode with constant offset to load the second number.
so my code changed like this:
ldx ops
ldy #ops
ldd 2,y
seems to work!
thanks anyway, berkeman!edit:
a follow-up question though: in assembly you can't just set a variable to a value, like you would in a high-level language, you always have to go through registers?
hope my question is clear :redface:
 
Last edited by a moderator:
EvLer said:
a follow-up question though: in assembly you can't just set a variable to a value, like you would in a high-level language, you always have to go through registers?
hope my question is clear :redface:
Sure you can. Just look a little farther bud.
 
for your first question can you use the co-processer registers or must you use only the main registers
 
i assumed main registers... in 68HC12 we have x,y,d,sp,i,pc registers.

got it, berkeman :wink:
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
14K
Replies
1
Views
4K