I have experience with high level programming languages like JAVA, but never programmed a hardware or used a low level programming language so learning Assembly was interesting.
Assembly is a low level programming language which is a millimeter higher than machine code. It is very strong and efficient. Computers and programmable devices can be programmed directly with assembly. In this language the programmer does not create classes, variables and objects, instead the programmer deals directly with registers, memory addresses and gives a direct instructions using the set of instructions of the microcontroller or the CPU.
Each programming language needs to be translated into the only thing that a CPU or microcontroller understands which is machine code. Assembly uses many compiler, one of them is gavrasm which converts the .asm to .hex which can be uploaded to the microcontroller.
I have installed gavrasm from this link, more information can be found in this link
After downloading the compiler, I have moved it to the home page of my Ubuntu, so I can use it globally by just calling it from the terminal using the command gavrasm
followed by the name of the .asm file.
Each microcontroller has it own set of instrucions, AVR 8-bit instrucions can be found in this link, in my case as a begginer I have used the following instructions to make a simple program
In C programming documentation, I have wrote a simple program which switch an LED when a Button is pressed (PCB design and fabrication can be found in electronics production documentation) so I have wrote the same progam in assembly as follows
; buttonled.asm
;
; PreFab Academy
; 21-DEC-2017
; by Ahmad Fares
; MIT License
;
; This program turns on the LED when the button is pressed
.device attiny44 ; defines which device to assemble for
.org 0 ; sets the programs origin
SBI DDRA,3 ; sbi reg,bit Sets a bit of a register.
; Setting DDRA bit 3 makes pin PA3 a (digital) output
CBI DDRB,2 ; sets PB3 as input
SBI PORTB, 2 ; activates pull up resistor in PB2
loop: ; label for main loop, labels must start with a letter and end with a colon
sbis PINB,2 ; skip the next instruction if PB2 is set (Button)
cbi PORTA,3 ; clear bit PA3 (switch on LED)
sbic PINB,2 ; skip the next instruction if PB2 is clear (Button)
sbi PORTA,3 ; set PA3 (switch off LED)
RJMP done ; jump to done
done:
RJMP loop ; relative jump to label called loop