Professional Documents
Culture Documents
Modul PBM 4 (Assembly Basic)
Modul PBM 4 (Assembly Basic)
Modul PBM 4 (Assembly Basic)
PERANCANGAN
BERBASIS
MIKROPROSESOR
Assembly Basic
Other programming
language
The CPU reads hex 0C01, R0 and R1 is added and the result is written to register
R0. This is executed like demonstrated in the picture.
First the instruction word (16 bit) is read from the flash and translated to executable
steps (1). The next step connects the registers to the ALU inputs, and adds their content
(2). Next, the result is written to the register (3).
If the CPU reads hex 9C23 from the flash, the registers R3 and R2 are muliplied and
the result is written to R1 (upper 8 bits) and R0 (lower 8 bits). If the ALU is not equipped
with hardware for multiplication (e. g. in an ATtiny13), the 9C23 does nothing at all. It doesn't
even open an error window (the tiny13 doesn't have that hardware)!
In principle the CPU can execute 65,536 (16-bit) different instructions. But because
not only 170 should be written to a specific register, but values between 0 and 255 to any
register between R16 and R31, this load instruction requires 256*16 = 4,096 of the 65,536
theoretically possible instructions. The direct load instruction for the constant c (c7..c0) and
registers r (r3..r0, r4 is always 1 and not encoded) is coded like this:
Addition and subtraction require 32*32 = 1,024 combinations and the target registers
R0..R31 (t4..t0) and source registers R0..R31 (s4..s0) are coded like this:
Assembler Code
LD A, 01H
LD = LOAD
H = Hexadecimal part of 01
Atmel Studio
PBM04_NAMA_NIM
4
Keterangan:
1. Menu Bar
2. Code Editor
3. Solution Explorer
4. Log Bar
C:\Users\pc_name\Documents\
Atmel
Studio\7.0\PBM04_NAMA_NIM\
PBM04_NAMA_NIM\
Pin Mapping
This line tells the assembler to include the m328p.inc file which you downloaded. You may
want to put this in a directory of similar include files and then change the above line to
point to it there.
ldi hregister, numberloads a number (0-255) into a upper half register (16-31)
Using binary is simplest though because of the way Ports and Registers work. We
will discuss the ports and registers of the atmega328p in more detail in future tutorials but
for now I'll just state that we are using r16 as our "working register" meaning that we are
just going to use it as a variable that we store numbers in. A "register" is a set of 8 bits.
Meaning 8 spots that can either be 0 or 1 (`off' or `on'). When we load the binary number
0b00100000 into the register using the above line we have simply stored that number in the
register r16.
Exercise
Please create a simulation using PROTEUS 7/8 of the following code above.
Please submit the result as a video (using screen recorder software that I’ve been attached on
GoogleDrive). The video explains the whole process of what you have done.
Post the video on the Forum or Email (in case POST system while under maintenance)
BETTER BOTH OF THEM.
DEADLINE APRIL,03,2020