Documente Academic
Documente Profesional
Documente Cultură
Experiment 2 & 3
Amish Suchak
4364508
University of Wollongong in Dubai
Task 1
Examine the following assembly code.
My observations:
The following code that was given in task 1 had quite a number of instructions that I was
not previously aware of that I was able to understand for my implementation. At first I started off
with understanding what each instruction did and tried to explain it in my own words.
This instruction was used to define the BCD1 as a value in register number 16. It was used so
that when we were to enter it in the body of the code, I would be able to use BCD1 and the
programmer would know that its value would be stored in r16.
This instruction was used in order to define all the pins in port B and port C as the outputs. It can
be seen in the simulation and also on the hardware. Whatever value it is that we would want to
display as LEDs or another form through the two ports. In this scenario, the LDI command was
used to store the binary value 11111111, I know this because of the 0b that was written before the
8 digits. It would have however been better to bitmask and enter these values into the ports rather
than doing so directly.
This instruction was used to define all the slots in the port A as the inputs. I noticed how the out
command was used because we are not dealing with registers, but with the ports.
in temp, PINA
com temp
mov BCD1, temp
andi BCD1, 0b00001111
For this set of instructions, we started off by saying that the input values are to be taken in from
the PINA. This could be done with the help of a lot of factors but for our case, we would be
inputting with switches. We then use the com instruction to complement the values that are taken
because of the hardware instructions. We then move the values that are taken from the temp into
BCD1 which is basically register 16. Lastly, we use an and gate to mask of the least significant 4
bits and perform the similar operation for BCD2.
In these instructions, we begin with moving the value from BCD1 into the temp register. We then
add temp and BCD2 which stores the value of the addition into the temp register. Then, the bits
are complemented due to the hardware of the AVR m8515 microcontroller and lastly, we output
the results into the PORTB. We then perform the same instruction for multiplication and display
the results in PORTC.
TASK 2
For task 2 of the experiment, I basically had to simulate the program and check the boxes
near PIN A in the I/O view. This is equivalent to inputting 10010110 into port A. This is also
the BCD numbers 0110 and 1001 or in decimal 6 and 9. Once that was done, I was able
to realize that the result of the addition of both the numbers was 15 and the multiplication of both
the numbers came out to be a value of 54 which is what we had initially expected. I also tried
running the code with different values other than 6 and 9 and found out that the code was able to
work properly.
Task 3
Modify the code so that PORTC outputs the difference between the two BCD
values instead of the multiplication. The instruction for subtraction is SUB.
Build and simulate the code. Ensure that it operates as expected
For task 3 of the experiment, it was quite simple to change the code to fit in the subtraction instead of the
addition. The main thing that had needed to be done was to delete the part of the code that said ADD and
changed it to SUB.
Task 4
Answer the following questions
What should 10100110 on PORTA give you on PORTB and PORTC if using the code
from task 1?
1010 0110 is binary 10 and 6. PORTB which is the addition of 10 and 6 would show a
value of 16. PORTC which is the multiplication of 10 and 6 would show a value of 60.
Assuming the input is 00111011. What should the output on PORTC be for the code in
task 3?
Answer:
.include"m8515def.inc"
LDI r16, 4
LDI r17, 9
STS 0x0060, r16
STS 0x0061 ,r17
ADD r17, r16
MOV r18,r17
STS 0x0062,r18
LDS r17,0x0061
SUB r17 , r16
MOV r19,r17
STS 0x0063, r19
LDS r17,0x0061
MUL r17, r16
MOV r20, r17
STS 0x0064,r17
LDS r17,0x0061
AND r17, r16
MOV r21, r17
STS 0x0065, r21
LDS r17,0x0061
OR r17, r16
MOV r22, r17
STS 0x0066,r22
LDS r17,0x0061
Analysis:
For the entirety of this code, I used mainly the STS and the LDS functions. The STS is used to
take a value from the register in order to store it into the dataspace. The LDS is used to retrieve
the value from the data space back into the register. In retrospect, what I could have alternatively
done is that instead of keeping on retrieving the value of r17 from 0x0061, I could have just
pushed the value of r17 into the stack and then continually popped it after every operation. Also,
I could have avoided the step where I move the value of the operation into another register by
storing the value directly into the data space.
Answer:
.include"m8515def.inc"
ldi r16,2
Main:
CPI r16,1
BREQ LABL1
CPI r16,2
BREQ LABL2
CPI r16,8
BREQ LABL3
LDI r17, 8
LABL1:
ldi r17,5
rjmp main
LABL2:
ldi r17,6
rjmp main
LABL3:
ldi r17,7
rjmp main
My analysis:
For this code, I focused on mainly the implementation of labels and how useful labels are.
Compared to C, labels act as functions. The new tool that I learnt in this project is how to use the
BREQ function. The BREQ literally translates to branch if greater than or equal to, meaning that
if the value is greater than or equal to the proposed value, branch to a label.
Task 5:
Answer the following questions in your lab book:
What values do you expect to be stored in each of registers r18 through r22 for the first
program?
I would expect the values of the various operations between the numbers 4 and 9. For
example, for ADD function, I would expect the value of 13, the SUB function would get the
value of 5, the MUL function would get the value of 36. For the AND and OR, it would take
the value into the binary form and perform an AND gate and an OR gate operation.
Yes
Not all registers are necessarily available for use. Registers 26 to 31 are reserved for index
registers. Additionally, some instructions can only be used on the upper half of the register
file (registers 16+).
Was there any Carry, Negative or Overflow issues observed in the operations?
Yes
In Task 3, what instructions were used to skip over the unneeded branches of the code?
BREQ was used to skip the remaining of the code and skip to that particular label.