Shop OBEX P1 Docs P2 Docs Learn Events
Using a WORD value in my Sx/B calculations — Parallax Forums

Using a WORD value in my Sx/B calculations

dufflingduffling Posts: 73
edited 2005-03-28 17:07 in General Discussion
Im having trouble working out how to compute WORD values ..

I understand a word is two bytes , i create a two byte array

number var byte(2)

and i realize that a word is the same as a 16bit binary value ..

but im finding it hard to get my head around how i can duplicate the word type in sx/b

i basically need to store 16bit numbers in an eeprom

previously i did this using Number.highbyte , number.lowbyte etc

if anyone has any Sx/b maths routines i can study

also

in assembly if i wish to count a 16bit number im using the Addb command to add a bit using status.0 , the carry bit
im still a bit in the dark as to how this command actually works.. ive studied the code numerous times.. and im missing something

thanks again
·

Comments

  • BeanBean Posts: 8,129
    edited 2005-03-28 12:46
    SX/B will handle the values much easier if you make them "normal" BYTE variables.

    numberL VAR BYTE
    numberH VAR BYTE
    working VAR BYTE

    ' add 8-bit to 16-bit
    numberL=numberL + working
    numberH = numberH + C

    The addb command expands to:
    SNB status.0
    INC variable

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "A problem well defined, is a problem·half solved."
    ·
  • RsadeikaRsadeika Posts: 3,837
    edited 2005-03-28 14:08
    I guess I need some explanation about this subject also. In PBASIC you can declare a variable in the following manner - 'thing1 VAR Word', which I assume makes thing1 16 bits, I think a Word is 2 bytes = 16 bits. Now, I tried, in SX/B, 'thing1 var byte (2)', could this be another way of 'creating' a Word, or did I miss sometning in the correct usage of byte. I tried this method in some conversion code, with no success.
  • BeanBean Posts: 8,129
    edited 2005-03-28 15:50
    BYTE(2) will create an array, which is accessed differently than normal BYTE variables. Requring more code to do the calculations. If you want to do it that way, here is some code that will work:


    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000

    number VAR BYTE(2) ' number(0) = LSB; number(1) = MSB
    working VAR BYTE

    Program Start

    Start:
    · PUT number,232,3 ' Store 1000 in number
    · working=100

    · ' Add "working" to "number"
    · ASM
    ··· MOV __PARAM1,working
    · · MOV FSR,#number
    ··· ADD IND,__PARAM1
    · · INC FSR
    ··· ADDB IND,C
    · · BANK $00
    · ENDASM

    END

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "A problem well defined, is a problem·half solved."


    Post Edited (Bean) : 3/28/2005 3:58:05 PM GMT
  • KenMKenM Posts: 657
    edited 2005-03-28 15:58
    Below is a 16 bit add routine in pure assembly. The lower bytes are term0 and prod0.

    You can put some initial values in term0 and prod0 and single step through the program watching what happens until you understand what is going on.

    term0··· ds 1

    prod0··· ds 1

    term1··· ds 1

    prod1··· ds 1

    mov W, term0
    add prod0, W

    mov W, term1
    snb C
    movsz W, ++term1
    add prod1, W
  • dufflingduffling Posts: 73
    edited 2005-03-28 16:59
    sorry i dont quite understand the line:
    'PUT number,232,3 ' Store 1000 in number'

    i may need some help with this .. everything else makes sense thou
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-03-28 17:04
    256*3+232=1000, understand now?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • dufflingduffling Posts: 73
    edited 2005-03-28 17:07
    whoops sorry i worked it out ! ......erk brain is at 4mhz today
Sign In or Register to comment.