Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Reading memory

  1. Jan 21, 2006 #1
    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 (Text):
         
            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.
     
  2. jcsd
  3. Jan 21, 2006 #2

    berkeman

    User Avatar

    Staff: Mentor

    Beats me. Can you provide pointers to the Assy language references please?
     
  4. Jan 22, 2006 #3
    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: Apr 21, 2017
  5. Jan 23, 2006 #4

    berkeman

    User Avatar

    Staff: Mentor

    Sure you can. Just look a little farther bud.
     
  6. Jan 31, 2006 #5
    for your first question can you use the co-processer registers or must you use only the main registers
     
  7. Feb 1, 2006 #6
    i assumed main registers... in 68HC12 we have x,y,d,sp,i,pc registers.

    got it, berkeman :wink:
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook