I have found an assembly code as follows
blink.asm
; blink.asm
; Pin Constant Values
; PD0 - 0
; PD1 - 1
; PD2 - 2
; PD3 - 3
; PD4 - 4
; PD5 - 5
; PD6 - 6
; PD7 - 7
; PB0 - 8
; PB1 - 9
; PB2 - 10
; PB3 - 11
; PB4 - 12
; PB5 - 13 - System LED
.DEF PTD = r16
.DEF PTB = r17
.MACRO Delay1
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
.ENDMACRO
start:
rcall init ; Initialize pins
loop:
Delay1
rcall setpinhigh
Delay1
rcall setpinlow
rjmp loop
init:
; Set pins 0-7 to low
ldi r16,(0<<PD7)|(0<<PD6)|(0<<PD5)|(0<<PD4)|(0<<PD3)|(0<<PD2)|(0<<PD1)|(0<<PD0)
out PORTD,r16
; Set pins 8-13 to low
ldi r17,(0<<PB5)|(0<<PB4)|(0<<PB3)|(0<<PB2)|(0<<PB1)|(0<<PB0)
out PORTB,r17
; Set pins 0-7 to output mode
ldi r18,(1<<DDD7)|(1<<DDD6)|(1<<DDD5)|(1<<DDD4)|(1<<DDD3)|(1<<DDD2)|(1<<DDD1)|(1<<DDD0)
out DDRD,r18
; Set pins 8-13 to output mode
ldi r19,(1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0)
out DDRB,r19
nop ; nop for settling down after pins set
ret ; return from subroutine
setpinhigh:
ldi PTD,1<<PD0
out PORTD, PTD
ret
setpinlow:
ldi PTD,0<<PD0
out PORTD, PTD
ret
delay:
ldi ZH,HIGH(65535)
ldi ZL,LOW(65535)
count:
sbiw ZL,1
brne count
ret
To blink the onboard LED of my Arduino uno (ATmega328P processor).
I tried to compile the code to hex by this command
avra blink.asm
But I receive
AVRA: advanced AVR macro assembler Version 1.3.0 Build 1 (8 May 2010) Copyright (C) 1998-2010. Check out README file for more info AVRA is an open source assembler for Atmel AVR microcontroller family It can be used as a replacement of 'AVRASM32.EXE' the original assembler shipped with AVR Studio. We do not guarantee full compatibility for avra. AVRA comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of avra under the terms of the GNU General Public License. For more information about these matters, see the files named COPYING. Pass 1... Warning : No .DEVICE definition found. Cannot make useful address range check ! Pass 2... blink.asm(62) : Error : Found no label/variable/constant named PD7 blink.asm(62) : Error : Found no label/variable/constant named PD6 blink.asm(62) : Error : Found no label/variable/constant named PD5 blink.asm(62) : Error : Found no label/variable/constant named PD4 blink.asm(62) : Error : Found no label/variable/constant named PD3 blink.asm(62) : Error : Found no label/variable/constant named PD2 blink.asm(62) : Error : Found no label/variable/constant named PD1 blink.asm(62) : Error : Found no label/variable/constant named PD0 blink.asm(63) : Error : Found no label/variable/constant named PORTD blink.asm(66) : Error : Found no label/variable/constant named PB5 blink.asm(66) : Error : Found no label/variable/constant named PB4 blink.asm(66) : Error : Found no label/variable/constant named PB3 blink.asm(66) : Error : Found no label/variable/constant named PB2 blink.asm(66) : Error : Found no label/variable/constant named PB1 blink.asm(66) : Error : Found no label/variable/constant named PB0 blink.asm(66) : Maximum error count reached. Exiting... done Used memory blocks: Code : Start = 0x0000, End = 0x0040, Length = 0x0041 Assembly aborted with 15 errors and 1 warnings.
How to fix these errors?
My OS is Ubuntu 16.04.
Advertisement
Answer
This error tell you that the assembler does not know what you mean by PD0, PD1…etc
Solution
instead of define registers and pin from scratch these definitions already there… you can download and use m328Pdef.inc
Add it in the same folder with your code then include it in the top of your code as following
.include "./m328Pdef.inc"
Note that: m328Pdef.inc is just some Register and Bit Definitions for the ATmega328P