Shop OBEX P1 Docs P2 Docs Learn Events
Assembly language help?? — Parallax Forums

Assembly language help??

SiriSiri Posts: 220
edited 2008-09-10 23:10 in Propeller 1
I am learning PASAM and have no previous experience with any machine languages.I have some experience with PBASIC and SPIN.
I have read both D'Silva's and Potatoheads - PASAM beginner literature and also most of the other available
material.
It would be very helpful if some one would explain in detail how the following code works - one step at a time
specially when the instruction is follwed by few conditions - that changes the original value.

Please explain this code as much detail as possible:

"Assembly language serial driver"

··················· ORG······················· 'no need to explain this


entry··········· mov··· t1,par
·················· add··· t1,#4· << 2

················· rdlong·· t2,t1
··················mov····· rxmask,#1
················· shl······· rxmask,t2················ ' I understand "masking"·I wan't to understand what is the logic

················ add······t1,#4
················ rdlong·· t2,t1
················ mov····· txmask,#1
·················shl······· txmask,t2

t1··········· res·· 1
t2··········· res··· 1

rxmask····· res··· 1
txmask····· res··· 1


Thank you.

Siri

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-09 17:35
    Added additional comments to the code below
    Siri said...
    I am learning PASAM and have no previous experience with any machine languages.I have some experience with PBASIC and SPIN.
    I have read both D'Silva's and Potatoheads - PASAM beginner literature and also most of the other available
    material.
    It would be very helpful if some one would explain in detail how the following code works - one step at a time
    specially when the instruction is follwed by few conditions - that changes the original value.

    Please explain this code as much detail as possible:

    "Assembly language serial driver"

    ··················· ORG······················· 'no need to explain this


    entry··········· mov··· t1,par······················ 'this is getting the parameter passed to the cog - in this case an address of a hub variable
    ·················· add··· t1,#4· << 2··············· 'this assumes there are a set of longs in hub memory and as longs are 4 bytes its movign the address 2 longs forward

    ················· rdlong·· t2,t1······················· 'read the value of the hub long
    ··················mov····· rxmask,#1············· 'this and next line is the same as spin |< i.e. it read a hub long that contained a pin no and converted it to a pin mask
    ················· shl······· rxmask,t2················ ' I understand "masking"·I wan't to understand what is the logic

    ················ add······t1,#4······················ ' change hub address to next long
    ················ rdlong·· t2,t1······················ 'this and next 2 do the same but with another pin, one will be the tx pin and one the rx pn
    ················ mov····· txmask,#1
    ·················shl······· txmask,t2

    t1··········· res·· 1······························· 'local memory in cog to hold a copy of the hub varialbe read via rdlong
    t2··········· res··· 1

    rxmask····· res··· 1·························· 'local memory in cog holding a pin mask
    txmask····· res··· 1


    Thank you.

    Siri
  • BaggersBaggers Posts: 3,019
    edited 2008-09-09 17:39
    Hi Siri, here goes.

    on initialising a cog the PARameter you send to it gets copied into PAR

    entry mov t1,par ' this copies PAR ( the parameter you supplied to the cog ) to t1
    add t1,#4<<2 ' this adds #4<<2 to t1 4<<2 = 16 as << = shift left so 4 shift left 2 times = 16

    rdlong t2,t1 ' read long from HubRAM addressed at t1, ( PAR+16 remember [noparse]:)[/noparse] ) and puts the value located there into t2
    mov rxmask,#1 ' stores 1 in rxmask (the # means the next value is an immediate number ie, it's not taken from a location at that address cogram )
    shl rxmask,t2 ' shifts left rxmask by t2 ( contents of HubRAM location PAR+16 remember )

    add t1,#4 ' adds 4 to t1 ( ie for this code example it points to the next long eg it's now PAR + 20 )
    rdlong t2,t1 ' read long from HubRAM address at t1 ( PAR + 20 ) and stores it in t2
    mov txmask,#1 ' stores 1 in txmask
    shl txmask,t2 ' shifts left txmask by t2 ( contents of HubRAM location PAR+20 remember [noparse]:)[/noparse] )

    ( then will probably do something weird, as you've not stopped the cog or kept it in a loop, the program counter will continue onto t1, which is a variable, not a valid instruction )

    basically this program will get a long at HubRAM PAR+16 and set bit 1 of rxmask, and shift it, in essence setting the bit of that corresponds to the value at that address. and same for txmask, but from PAR+20

    Hope this helps you,

    Baggers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • SiriSiri Posts: 220
    edited 2008-09-09 18:18
    Baggers,



    Thank you very much for the quick reply.

    I will digest evry bit of what you posted.



    Siri
  • SiriSiri Posts: 220
    edited 2008-09-09 20:15
    Baggers,
    Can you explain to me why- this line of code was necessary
    " add t1,#4<<2 ' this adds #4<<2 to t1 4<<2 = 16 as << = shift left so 4 shift left 2 times = 16"


    Is it wright if I say what this did was to make t1= par+16 and - why was not done by just coding as: add t1,#16

    Thanks

    Siri
  • AribaAriba Posts: 2,687
    edited 2008-09-09 20:55
    Siri said...

    Is it wright if I say what this did was to make t1= par+16 and - why was not done by just coding as: add t1,#16
    Yes, this makes t1=par+16, it is only written as #4<<2 to show that this are 4 longs (and not 8 words or 16 bytes).

    The addition of 4 longs is done because the first 4 longs in the Spin parameter array contain no parameters for the Assembly initalisation section. This first 4 longs are pointers which are initialized from Spin to read and write the input and output buffers and are used later in the Assembly code (assuming the code comes from FullDuplexSerial).

    Andy
  • SiriSiri Posts: 220
    edited 2008-09-10 23:10
    Thank you - Tim,Andy,Baggers for helping me with PASM

    I am sure I will have more later.

    Thanks again.

    Siri
Sign In or Register to comment.