Loading 16-bit Numbers into D and X Registers

  • Thread starter Thread starter EvLer
  • Start date Start date
  • Tags Tags
    Numbers
Click For Summary
The discussion centers on loading two 16-bit numbers from memory into D and X registers for division using the FDIV instruction. The original poster is confused about how to load separate 16-bit values into these registers, given that the memory reserved is 4 bytes for two 16-bit numbers. They later discover a solution by loading the Y-register with the address of the "ops" variable and using indexed addressing to load the second number. A follow-up question arises regarding variable assignment in assembly language, clarifying that values must be assigned through registers rather than directly. The conversation concludes with a confirmation of understanding about register usage in the 68HC12 architecture.
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
2K
  • · Replies 7 ·
Replies
7
Views
1K
  • · 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
3K