Assembler: please kick me in the right direction


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Ok, I've researched each instruction and these 5 have no direct translations:

    PUSH, push direct byte onto stack
    POP, pop direct byte from stack
    MUL, multiply
    ADDC, add into accumulator
    MOVC, move code byte to accumulator

    I wouldn't be surprised if the equivalent PIC Macro instructions are staring me in the face, but I don't want to start guessing. Here is some code to show the context the commands are used in:

    ; write an ASCII character to the display
    ; The font file starts at ascii 32 (blank). The default font is 8x8 pixels
    ; INPUTS - character in register A
    write_char:
    push dph
    push dpl
    clr c
    subb a,#32 ;ascii font with blank
    mov b,#8 ;multiply by 8 (8 bytes/char)
    mul ab
    add a,#low(font) ;add to font table address
    mov dpl,a
    mov a,b
    addc a,#high(font)
    mov dph,a
    mov r0,#8 ;8 bytes/char
    wbyte: clr a
    movc a,@a+dptr
    acall write_data
    inc dptr
    djnz r0,wbyte
    pop dpl
    pop dph
    ret

    8051 assembler reference here:
    http://www.ece.umr.edu/computing/uni...e/tasking/asm/

    PIC Macro assembler reference:

    Robert
    Attached Files Attached Files
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Robert,

    The PUSH and POP were apparently used to save 2 variables that were used in the write_char: routine. You can just use separate variables to temporarily store the two bytes, instead of trying to use the stack.

    MUL can be replaced with the MUL?BBB or MUL?BBW macro.

    For the addc and movc, you can either manipulate the EEADDR, EECON and EEDATA registers manually, or you could break out of ASM and use the READCODE statement to get the byte first, then do the ADDWF or MOVWF.

    HTH,
    Darrel
    Last edited by Darrel Taylor; - 24th December 2005 at 19:36.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default PUSH & POP conversion

    Like this?


    dph data 42h <--- add this line with existing DATA statement
    dpl data 43h <--- add this line with existing DATA statement


    write_char:
    push dph <--- delete this line
    push dpl <--- delete this line
    ...
    mov dpl,a
    ...
    mov dph,a
    ...
    pop dpl <--- delete this line
    pop dph <--- delete this line
    ret

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    "MUL can be replaced with the MUL?BBB or MUL?BBW macro."

    Darrel, can you point me to some reference on macros? I Googled but did not find anything relevant (that I could see).

    The MeLabs PM manual didn't have any mention for 'mul' or 'bbb'.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I was thinking something more like this...
    Code:
    dph_save VAR BYTE
    dpl_save  VAR BYTE
    
    ASM
    write_char:
        MOVE?BB  dph, _dph_save
        MOVE?BB  dpl, _dpl_save
    
        push dph <--- delete this line
        push dpl <--- delete this line
    ...
    
    ...
        pop dpl <--- delete this line
        pop dph <--- delete this line
    
        MOVE?BB  _dph_save, dph 
        MOVE?BB  _dpl_save, dpl 
    return
    
    ...
    
    ENDASM
    And, here's a little more info on the MOVE macro's
    http://www.picbasic.co.uk/forum/showthread.php?p=2009

    .
    DT

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default MUL conversion

    What type of variables are the variables a, b and c considered? My first quess would have been a work register, but I'd like to be sure.

    Since there are only 2 variables in the equation, the new command should be MUL?xx, right?

    (available letters seen in your reply to PIC Beginner in other thread)

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    This page describes the 8051 registers, but the whole site is pretty good too.
    http://www.8052.com/tutbregs.phtml#R%20Registers

    The MUL?xxx macro usually has 3 paramaters, the third one is the result of multiplying the first two.

    For instance, if you had the following variables ...
    Code:
    A  VAR  BYTE
    B  VAR  BYTE
    Y  VAR  BYTE
    Z  VAR  WORD
    THEN ...
    Code:
      this ASM macro              is same as this PBP statement
      ---------------------       -------------------------
        MUL?BBB   _A, _B, _Y          Y = A * B
        MUL?BBW   _A, _B, _Z          Z = A * B
        MUL?BWW   _A, _Z, _Z          Z = A * Z
    And, you can see that often it's easier to just jump out of ASM and handle it in Basic.

    ------------------
    If you do use the MUL? macros, there's something else you have to do to get them to work. Since, they are from the PBPPIC14.MAC file, they don't automaticaly get included with the project. So you have to Trick PBP into thinking it needs those macros.

    This bit of code doesn't use any Program space since the ifdef keeps it from being compiled. But PBP sees the statements and includes any macros that are associated with them.
    Code:
    @  ifdef DoNotCompile                        ' Macro to include
           R0.LowByte = R0.LowByte * R0.LowByte  ' MUL?BBB
           R0 = R0.LowByte * R0.LowByte          ' MUL?BBW
           R0 = R0.LowByte * R0                  ' MUL?BWW
    @  endif
    But then, If you do it in Basic, you don't have to worry about it.

    Merry X-Mas,
    Darrel
    Last edited by Darrel Taylor; - 25th December 2005 at 21:52.

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    I'm going with basic for the multiplication. Only problem is that table 4.1 in this document is confusing:
    http://xess.com/manuals/asm51.pdf

    The entry for MUL is:

    B x A --> B,A

    Ok, so what does that mean? The result is placed in both A and B? In addition, the result is accumulated in the first variable. I expected something similar, either in the first, or in the second, but not both. Obviously I'm misunderstanding something here.

    I tried finding Note 7, but I can't see it anywhere.

    Robert
    Attached Images Attached Images  
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. PIC assembler forum?
    By Lajko in forum Off Topic
    Replies: 1
    Last Post: - 29th September 2008, 05:34
  3. Assembler problem
    By om3bc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th March 2008, 19:12
  4. Am I reading this assembler correctly?
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 13th November 2007, 12:20
  5. Which assembler are you using?
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st November 2005, 20:34

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts