Can someone please tell me why this code would not compile (Assembly)?

Thread Starter

specs365

Joined Mar 14, 2019
12
Hi, I'm really new to assembly and really struggling to understand it, but i have to as its needed for a class. I get a "symbol not defined (delay)" error for the following. Why? (P.S> the delay part isn't done yet)
Code:
      title         "Our first Assembler program"
        list          P=PIC18F45K22 ; processor type - include in your test & exam
                                  ; code so we can see you selected the correct
                                  ; device
        #include    "p18f45K22.inc"
;
; ------------- 
; PROGRAM START 
; -------------
;
        org         0h             ; startup address = 0000h
     

start     movlw            0xFF         ; move 11111111b to W register
        movwf         PORTA        ; move W to port A
        movlw         0x00         ; move 00000000b to W register
        movwf         PORTA        ; move W to port A
        goto        delay
        end         

delay        nop
        nop
        nop
        nop
        goto        start
Mod edit: Added code tags
 

ericgibbs

Joined Jan 29, 2010
8,723
hi 365,
Welcome to AAC.
My assembler would report an error for the subroutine not having a ':' colon symbol.
delay nop

try
delay: nop

E
 

jpanhalt

Joined Jan 18, 2008
7,876
From MPASM manual
1.7.1.1 LABELS
A label is used to represent a line or group of code, or a constant value. It is needed for
branching instructions (Example 1-1).
Labels should start in column 1. They may be followed by a colon ( : ), space, tab or the
end of line. Labels must begin with an alpha character or an under bar (_) and may
contain alphanumeric characters, the under bar and the question mark.
Labels must not:
• begin with two leading underscores, e.g., __config.
• begin with a leading underscore and number, e.g., _2NDLOOP.
• be an assembler reserved word (see Section 3.3 “Reserved Words and
Section Names”).
Labels may be up to 32 characters long.
You seems to have everything starting in the first column . Maybe the Assembler got confused. Try this when posting: [code=MPASM] <insert code>[/code]

Most important, your "END" directive is misplaced. The Assembler didn't see anything after it, like your delay. Put the END after the delay.
 

MrChips

Joined Oct 2, 2009
19,270
Your "goto delay" does not serve much purpose.
Eventually you will learn proper program structure and how to use subroutines.
In the meantime, move "end" to the bottom of the code.
btw, if you are hoping to see something happen, good luck with that.
Code:
org         0h             ; startup address = 0000h
   
start movlw            0xFF         ; move 11111111b to W register
        movwf         PORTA        ; move W to port A
        movlw         0x00         ; move 00000000b to W register
        movwf         PORTA        ; move W to port A

delay  nop
        nop
        nop
        nop
        goto        start

        end
 

jpanhalt

Joined Jan 18, 2008
7,876
For once -- just once -- I'd like to see .asm taught without the concept of hard-coded blocking delay.
Oh, how many minds have been crippled by this? Most here on AAC, it seems.
Probably none. Maybe there is nothing else you want to or can do while the delay is running -- like when simply flashing an LED.

Sure, a timer and interrupt can be used, but perhaps that should be taught once the coder has more experience and needs to do that. Doesn't C also block when calling a delay in ms per se?
 

MrChips

Joined Oct 2, 2009
19,270
If I coded in C, I wouldn't use delay() either.

IMHO: if your MCU has the time to idle and do nothing but waste power, you are using the wrong part for the problem.

No one is going to pay for that skill.
You gotta learn to walk before you can run.
 

MrAl

Joined Jun 17, 2014
6,469
Yeah....but you don't learn to walk by running in molasses.
Hi,

Well how would you do it?

What it looks like to me is that the 'delay' token is not being seen in the subroutine because 'end' comes before the 'delay' subroutine so the compiler simply does not see the actual routine although it sees the call. So it sees a call to an undefined token and so generates the error message.
 

jpanhalt

Joined Jan 18, 2008
7,876
I think what he is referring to is about as close to multi-tasking as you can get. Namely, if you have a process that requires an action every 104 us (say a 9600 baud communication protocol), instead of using a delay, you can set up a timer to give an interrupt every 104 us. That lets you do a lot of other things in the interim (at 32 MHz, 104 us/0.125 us = 832 instructions of 1 Tcy each).

That is just one example. As delays get longer, it gets more important to do.

My interest is in helping the TS to the thrill of his first flashing LED. Of course,"thrills" are hard to sell, except maybe in Nevada.
 

MaxHeadRoom

Joined Jul 18, 2013
19,014
Although that delay of about half a dozen machine cycles is not going to be very long in order to flash a LED!
And with one instruction ON time!
Max.
 

jpanhalt

Joined Jan 18, 2008
7,876
Wow, that is your first attempt at Assembly in December, 2016? I thought you had be at it a lot longer.
 

joeyd999

Joined Jun 6, 2011
4,239
Wow, that is your first attempt at Assembly in December, 2016? I thought you had be at it a lot longer.
Is this directed at me? If so, try to comprehend some of the words (and numbers!) that make up the body of the blog post.
 

MaxHeadRoom

Joined Jul 18, 2013
19,014
I prefer to place the colon after labels and have them on a separate line.
A habit from the PDP and 8080 days I guess.
Also the colon helps in a search to distinguish the label from the call.
Max.
 
Top