ECE 425 Homework 2 Solution
1)
Use effective addressing in a short program to take four 32 bit constant values from a locations
starting at a label TABLE in your code and place them in RAM starting at 0x40000100.
;Program is a short loop
;Initialization
MOV R0,#0
;R0 WILL COUNT NUMBER OF VALUES AND INDEX
ADR R1,TABLE ;R1 POINTS TO BEGINNING OF TABLE
LDR R2,=0x40000100 ;R2 POINTS TO RAM LOCATION
LOOP
;TOP OF LOOP
LDR R3,[R1,R0,LSL#2] ;GET VALUE FROM TABLE
STR R3,[R2,R0,LSL#2] ;PUT VALUE IN RAM
ADDS R0,R0,#1 ;INCREMENT INDEX BY 1. LSL#2 MULTIPLIES BY 4.
CMP R0,#4 ;TEST IF DONE
BNE
LOOP ;LOOP IF INDEX IS NOT EQUAL TO 4
2) Write a short program to set bits 17 and 18 to 1 in a peripheral register at 0xE0001C00. DO NOT
CHANGE ANY OTHER BITS.
;USE READ, MODIFY, WRITE
LDR R0,=0xE0001C00 ;PUT ADDRESS OF REG. IN R0
LDR R1,[R0] ;READ REGISTER
MOV R2,#0x60000 ;PUT MASK IN R2. BITS 17 AND 18 SET
ORR R1,R1,R2 ;MODIFY
ORing SETS PROPER BITS. LEAVES OTHERS ALONE
STR R1,[R0] ;WRITE VALUE BACK TO REGISTER
3) If an eight bit register had the binary value 01110101 and was to be evaluated in Q4 notation,
what would its value be in decimal?
Least significant four bits are binary decimal = 0.25 + 0.0625 = 0.3125. Most significant four bits
are integer =7. Total value = 7.3125.
4) If an eight bit register had the binary value of 10110011 and was to be evaluated as a signed
integer, what would be its decimal value? If it was to be evaluated as an unsigned integer, what
would be its decimal value?
For signed, weights of integers that are one are -128 +32 +16 +2 +1 = -77 For unsigned, the weights would be 128+32+16+2+1=179
5) Write the values of the following binary numbers in hexadecimal notation (don’t use a
calculator):
Group bits by fours, starting at LSB and write hexadecimal integer.
11000101 0xC5
0011010111110110 0x35F6
101101110000111001011101 0xB70E5D
6) If R0 contains 0x1F, what would be the value of the Z (zero) flag and the N (negative) flag after
the following instruction was executed? What would be the value of R0?
CMP R0, #1E
CMP evaluates as R0 – 0x1E (there is typo in homework). Since
0x1F is greater than 0x1E, the Z flag would be clear (0) and the N
flag would be clear (0). Since CMP affects no registers other than the
flags, R0 would remain 0x1F.
7) If R0 contains 0x4 and R1 contains 0x5, what would be the values of all flags (NZCV) and the
values of R0 and R1 after the following instruction is executed?
SUBS R0, R0, R1
The result of the instruction is 0xFFFFFFFF and this is in R0.
R1 is unchanged and remains 0x5. The result has bit 31 set, so the N
flag is set (1). The result is non-zero, so the Z flag is clear (0).
The result of the subtraction is negative, so the C flag is clear (0).
The result of the operation would be interpreted as -1 if the values
were considered signed, therefore the V flag is clear (0). Another way
to look at this is the addition of -5 to +4 in binary, 32 bit form.
There is a carry into the 31st bit and a carry out. The V flag is the
EOR of these two carries and would be 0.
8) Write a short program to set bits 8 through 15 in a peripheral register at 0xE001C010 to
01101001 with the least significant bit in bit 8. DO NOT CHANGE ANY OTHER BITS.
Since we are setting some bits and clearing others we have to use an “erase” mask along with
the value mask. We would read in the register values and use the erase mask to clear all bits 8
through 15 to zero and then OR our desired values with the result.
LDR R0,=0xE001C010 ;PUT THE REG. ADDRESS IN R0
LDR R1,[R0] ;READ THE REGISTER VALUE
LDR R2,=0XFFFF00FF ;LOAD ERASE MASK INTO R2
LDR R3,=0X6900 ;LOAD VALUE MASK INTO R3
AND R1,R1,R2 ;CLEAR BITS 8-15 - MODIFY
ORR R1,R1,R3 ;SET ONE BITS IN REGISTER AS IN MASK. STR R1,[R0] ;WRITE VALUE BACK TO REG. ADDRESS
9) After the code snippet below is executed, what is the value in R0?
MOV R0, #0x11
MOV R1, #0x10
SUBS R0, R0, R1
MOVLT R0, #1
MOVGT R0, #2
MOVEQ R0, #3
The subtraction would evaluate as 0x11 – 0x10 = 0x1, which is
positive. The conditional execution treats the numbers as signed.
The GT suffix is identified as SIGNED > in the mnemonic table. The
instruction with that suffix is the only one that will execute and R0
will contain the value 2.