Experiment 1 – Lab Report
By: Kushal Galrani (EE24B034) and Kritigha Shri
(EE24B033)
Aim: To simulate a program written in AVR assembly for
atmega8 on the computer using microchip studio, and
inspect the register and memory values during run.
Apparatus Required: Windows computer with Microchip
Studio installed
Implementation:
Problem 1 (Common 8-bit mathematical operation): Given
two 8- bit binary words (byte), compute the sum and store it
in a register.
Problem 2 (16-bit addition using a 8-bit processor): Given two
16- bit binary words (byte), compute the sum and store it in a
register.
Problem 3 (Multiplication of two 8-bit numbers): Given two
8- bit binary words (byte), compute the product and store it
in a register.
Problem 4 (Largest of number given): Given a finite set of
binary words, identify the largest in the given set.
Note that my code uses the little endian format to store the
numbers. i.e., 0xab12 is stored as 0x12, 0xab
.cseg
ldi r16, 4; size of the list
ldi ZH, high(list<<1); initialize Z to point to "list", for use with
LPM
ldi ZL, low(list<<1)
ldi r17, 0; LSB of max
ldi r18, 0; MSB of max
loop:
lpm r19, Z+; LSB of current num
lpm r20, Z+; MSB of current num
cp r18, r20; MSB(max) - MSB(num)
brlo setmax; if MSB(max) < MSB(num)
; now MSB(max) >= MSB(num)
brne continue; if MSB(max) != MSB(num) ==> MSB(max) >
MSB(num)
; now MSB(max) == MSB(num)
cp r17, r19; LSB(max) - LSB(num)
brlo setmax; LSB(max) < LSB(num)
; now LSB(max) >= LSB(num), so definately no replacement
rjmp continue
setmax:
mov r17, r19
mov r18, r20
continue:
dec r16
brne loop
; save r17 LSB(max) and r18 MSB(max) at 0x60 in SRAM in
little endian form
sts 0x60, r17
sts 0x61, r18
halt: rjmp halt; program over
list: ; note that list is stored in little-endian format (LSByte
first, then MSByte)
.db 0x12, 0x34; 0x3412
.db 0x11, 0x34; 0x3411
.db 0x13, 0x34; 0x3413
.db 0xff, 0x33; 0x33ff
Conclusion:
Microchip Studio can be used to simulate a program written
for AVR. Further, we can pause the execution at certain points
to inspect values of register and memory locations which is
extremely useful for debugging.