Loading 16-bit Numbers into D and X Registers

  • Thread starter EvLer
  • Start date
  • Tags
    Numbers
In summary, the code needs to load two 16-bit numbers from memory and divide one by the other. The code was given with comments that explain how to do it. The first step is to load the Y-register with the address of the "ops" and then use indexed addressing mode with a constant offset to load the second number.
  • #1
EvLer
458
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
  • #2
Beats me. Can you provide pointers to the Assy language references please?
 
  • #3
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:
  • #4
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.
 
  • #5
for your first question can you use the co-processer registers or must you use only the main registers
 
  • #6
i assumed main registers... in 68HC12 we have x,y,d,sp,i,pc registers.

got it, berkeman :wink:
 

What is the purpose of loading 16-bit numbers into D and X registers?

The purpose of loading 16-bit numbers into D and X registers is to store data in a specific location in memory. These registers are used in computer processors to hold temporary data while performing calculations and operations.

How do you load a 16-bit number into the D and X registers?

To load a 16-bit number into the D and X registers, you can use the LDD and LDX instructions. These instructions take the value of the 16-bit number and store it in the specified register. You can also use the LDD instruction to load a 16-bit number directly into the D register, or the LDX instruction to load a 16-bit number directly into the X register.

What is the difference between loading a 16-bit number into the D and X registers?

The main difference between loading a 16-bit number into the D and X registers is the type of data that can be stored. The D register can hold signed numbers from -32768 to 32767, while the X register can hold unsigned numbers from 0 to 65535. Additionally, the D register is commonly used for arithmetic operations, while the X register is commonly used for addressing memory locations.

Can you load multiple 16-bit numbers into the D and X registers at once?

Yes, it is possible to load multiple 16-bit numbers into the D and X registers at once using the LDD and LDX instructions. These instructions allow you to specify a register and an offset, so you can load data from consecutive memory locations into the specified register.

Are there any limitations or considerations when loading 16-bit numbers into D and X registers?

When loading 16-bit numbers into D and X registers, it is important to consider the size and type of data that can be stored. Additionally, the number of available registers and their usage in the rest of the program should be taken into account to avoid conflicts. It is also important to ensure that the data being loaded is not larger than 16-bits, as this could result in data loss.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
807
  • Engineering and Comp Sci Homework Help
Replies
7
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
634
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
13K
Back
Top