Exploring the LPC 4088 Instruction Set’

Week 1
Explain carefully what the repeated ADD instruction is doing each time it runs?
The Add instruction is basically adding a byte value to the accumulator, the results is then stored back in the accumulator.
Explain carefully what the repeated SUBS instruction is doing each time it runs. What is the effect on the condition codes?
The SUBB instruction on the other hand, subtracts the specified byte variable as well as the carry flag from the accumulator.  Based on the lab work, the R0 is always being decremented, and then it uses the s suffix and the role for this is to update the flag.
Can you explain what the BNE instruction does, with examples from your steps?
BNE stands for branch if not equal and it’s basically used in a machine language that branches or in other words jumps to a particular address, if and only if the zero flag is clear. However, if the CPU runs into the BNE instruction when the zero flag is set, the instruction of the CPU will carry on following the BNE instead of taking the jump.
In addition, if the outcome of an operation or a byte is retrieved from the memory is equal to zero, the BNE instruction will check for any zero results. In the example below, there is a loop used…
(Change )Since the zero flag is set if the result of an operation, or a byte retrieved from memory, equals zero, one of the uses for BNE is to check for such zero results. In this example, BNE is used to keep a loop”going” until the “count” in the X index register reaches zero:

As you step through the code, you will notice that the value of the PC is sometimes 2 or 4 more than the value in the assembly addresses displayed and discussed above. Can you explain why this should be?

Updating the PC means to set values of registers to the next instruction that is going to be executed. However, if the instruction is jump or branch, then the next instruction is to execute the instruction in the memory.  So the reason for the PC value is altering 2 or sometimes 4 more than the value in the assembly is because the instruction at times is 4 bytes of the pc or 2 bytes. Therefore, the next address in the memory can be PC + 4 or PC + 2 depending on the byte size. In addition, the pc may change to other address if there is a jump or a branch.

Week 3
Diagram one that is illustrated with the use of ‘S’ suffix
Instruction     Condition flag
MOVS R0, #0    N=0, Z=1, C=0, V=0
MOVS R1, #1    N=0, Z=0, C=0, V=0
MVNS R2, #0
N=1, Z=0, C=0, V=0
MOVS R3, #0x80000000
N=1, Z=0, C=1, V=0
MOVS R4, R0
N=0, Z=1, C=1, V=0
MOVS R5, R1    N=0, Z=0, C=1, V=0
MOVS R6, R2    N=0, Z=1, C=1, V=0

Diagram two that is illustrated without the use of the ‘S’ suffix
Instruction     Condition flag
MOV R0, #0    N=0, Z=0, C=0, V=0
MOV R1, #1    N=0, Z=0, C=0, V=0
MVN R2, #0
N=0, Z=0, C=0, V=0
MOV R3, #0x80000000
N=0, Z=0, C=0, V=0
MOV R4, R0
N=0, Z=0, C=0, V=0
MOV R5, R1    N=0, Z=0, C=0, V=0
MOV R6, R2    N=0, Z=1, C=0, V=0

Question one)
Initially the program starts by moving the value of 0 to the register 1(MOVS R0, #0), and then all of the condition flags eventually update. However, all the condition flags will remain 0 apart from condition Z, which will change to true. The second step is the same step as the first one, value one will change the register 1 (MOVS R1, #1). After this all of the condition flags will be changed. However, since the register one is one, all of the condition flags will become 0.Third instruction differs from all the previous instructions. The reason it differs is because it performs a logical not operation. So, instead of making register 2 to 0, it will change the value to 1; for instance, 0000 0000 becomes 1111 1111. This will result to make condition flag N to 1, as there is a negative number.
The next instruction which is MOVS R3, #0x80000000 is basically moving the value of #0x80000000 to register 3, and then updating the condition flags. However, the condition flag of N will be 1 because there will be a value of one in the left hand side of the binary number, and the condition of C will become one as there will be a carry of one.
Ultimately, the last 3 instruction will behave in the same manner, by moving the value of one register to the other which then will update the condition flags as displayed in diagram 1.

READ ALSO :   Brokerage Firms.

The diagrams that are illustrated in the top use the ‘S’ suffix (diagram one) and the other doesn’t use the ‘S’ suffix (diagram 2). As a result, by not having the ‘S’ suffix effect in diagram one, the condition flags are updated each time the program is running. On the other hand, diagram two, doesn’t have the effect of the ‘S’ suffix, therefore the condition flags are never updated each time the program is ran.
Question 2)
Instruction    Condition flag    Register 0    Register 3
MOVS R0, #1    N=0, Z=0, C=0, V=0    0x00000001    0x00000002
MOVLE R3, R0    N=0, Z=0, C=0, V=0    0x00000001    0x00000002

Instruction    Condition flag    Register 0    Register 3
MOVS R0, #0    N=0, Z=1, C=0, V=0    0x00000000    0x00000002
MOVLE R3, R0    N=0, Z=1, C=0, V=0    0x00000000    0x00000000

Instruction    Condition flag    Register 0    Register 3
MOVS R0, #-1    N=1, Z=0, C=0, V=0    0xFFFFFFFF    0x00000002
MOVLE R3, R0    N=1, Z=0, C=0, V=0    0xFFFFFFFF    0xFFFFFFFF

The LE instruction that is used in the program checks whether the condition flags are set to zero in order for the register to be enabled to move from one value to another, the only two condition flags that needs to change are Z and N.  For instance in diagram one, neither of the conditions was set to one, either N or Z needs to be 1 in order for the operation to happen.
In diagram number 2, the condition flags differ from diagram number one. This time the Z value has is set to one, therefore the instruction will now work and change. For instance; the value of 0 will move to register 0 (MOVS R0, #0), and then MOVLE R3, R0 will check for conditions Z and N for any changes, in this case Z has changed to 1. Therefore, register 0 will now move to register 3.
In the final diagram which is diagram number 3, it is kind of similar to diagram 2. However, this time the condition flag of N is set to one, which is a negative one. So,  MOVS R0, #-1, the negative one will now move to Register 0. Then the MOVLE R3, R0, will check the condition flags, which is N and will move the value of register 0 to register 3.

Question 3)
Instruction    Condition flag    Register 0    Register 3
MOV R0, #7    N=0, Z=0, C=0, V=0    0x00000007    0x00000002
MOVS R3, LSL #4    N=0, Z=1, C=0, V=0    0x00000007    0x00000070

Instruction    Condition flag    Register 0    Register 3
MOV R0, #7    N=0, Z=0, C=0, V=0    0x00000007    0x00000002
MOVS R3, R0R, LSL #4    N=0, Z=0, C=0, V=0    0x00000007    0x70000000
The diagram that is illustrated at the top shows a program that has performed the following instruction. The outcome of this instruction which is (MOVS R3, R0, LSL #4) will begin by moving the value of register 0 to register 3. Then, it will perform the operation of logic shifting 4 bytes to the left, which will result register 3 to become 0x00000007.

This diagram on the other hand, uses something different to the previous diagram. In this case it uses, ROR which is rotate right. Moreover, the result in this case will be 0x70000000, because the value of 7 was forced to be moved to the right 4 bits.

Question 4)
MOV R0, #7
ADD R1, R0, R0,LSL #3
SUB R1, #1
RSB R0, R1
The behaviour of the following code differs a lot from the previous codes that were explained earlier.  First it moves the value of 7 to the register 0. Then, the second instruction was to make a logic shit to the left on one of the register 0, which is then moved three bits to the left. The outcome of this becomes 0x0000038 and then it adds this result to the value register 0, and the outcome of that will be 0x000003F. the final step will be moving the new value to the register one.

Question 5)
ORR R1, #0x1F
MOV R0, R1, LSL #3
BIC R0, #5
The behaviour of the following instruction uses different things, like the logic ORR as well as BIC which is using the logic OR and AND. The code first starts by preforming the logical ORR instruction, so performing Logical OR of the value #0x1Fto the current value of register one. This then will be placed into register one.
On the other hand, the second instruction is basically performing a logical shift left of 3 bits to the left. The new value of register one will be 0x80000F8, then this value will be placed into the register 0.
The third and final instruction performs something else, which is BIC that stands for bit clear. At first it performs a logical not to the value of 5. Then, it will perform the second operation which is the logical AND operation. The two values that will perform this operation are the new value from the answer mention plus register 0. The answer will be 0x80000F8, which is seems the same value as the value that was initially mentioned before.
Question 6)  (ASK micheal about CMN, TEQ and TST)
First example
CMP R0, #229
CMN R0, R1
TST R0, R1
TEQ R0, R1
This is one of the three results from the example that I have made in order to see any changes of the condition flags. Therefore, this test will first compare the value of 229 to register 0, and then this will give us a result of the carry flag to become true, as the register value is the same. The condition flag in this case will be true in both the Zero flag as well as the Carry flag.
Second example
CMP R0, #228
CMN R0, R1
TST R0, R1
TEQ R0, R1
However, in the second example the result in the condition flag differs. It again takes the value of 228 (which is different from the previous example) and compares it to register 0. The results of condition flag will be Negative in the condition flag.
Third test
CMP R0, #230
CMN R0, R1
TST R0, R1
TEQ R0, R1

READ ALSO :   Ted Bundy

In the final test, the condition flag again becomes different. It will again take the value of 230 (which is higher than the other 2 tests) and place it in the register as well as it compares it. The condition flag will now update and the only thing that becomes true is the Negative condition.

Week 4
Question 2)
DCDU is the same as the DCD, by allocating multiple words of memory, aligned in 4 byte boundaries as well as it initialises the runtime contents of the memory. DCDU, however, is different because the memory alignment is arbitrary.
Question 3)Explain carefully what lines 9-11 are doing
Initially the program starts at line 9 which is (LDR r3, =parameters) which is loading the memory address of the parameter to the register 3. Secondly, the next line which is line 10 (LDR r0, [r3]), this will load register 0 from the memory address register 3. The final step of the program on line 11 is as follows (LDR r2, [r3, #4]). First it adds 4 bytes onto register 3 and then it will load register 2 from the memory address register 3. The 4 bytes is there so that there is a space in the address for the register that is stored, which is register 0.
Question 4)
The begging of the line 9 (MOV R2, #0) it is basically moving the register of 0 and storing the value in register 2. Line 10 (LDR R1, =parameters), it is loading the memory address of the parameter to register 1.  In line number 11 it is starting the loop. Next, line number 12 (LDRH R0, [r1], #2),

Week 5
Question one
After stepping from line 9 to 10, register LR doesn’t change at all and register PC changes to E8 this will be incremented by 4. After the second instruction is executed the LR will store 0xED which will be the return address for the pc address. However, the PC instruction will hold the next address, in this case 0xEE.

Question two)
Loop count     Register 1    Condition Flags
1    0x4000    N=0, Z=0, C=1, V=0
2    0x2000    N=0, Z=0, C=1, V=0
3    0x1000    N=0, Z=0, C=1, V=0
4    0x800    N=0, Z=0, C=1, V=0
5    0x400    N=0, Z=0, C=1, V=0
6    0x200    N=0, Z=0, C=1, V=0
7    0x100    N=0, Z=0, C=1, V=0
8    0x80    N=0, Z=0, C=1, V=0
9    0x40    N=0, Z=0, C=1, V=0
10    0x20    N=0, Z=0, C=1, V=0
11    0x10    N=0, Z=0, C=1, V=0
12    0x8    N=1, Z=0, C=0, V=0
13    0x4    N=1, Z=0, C=0, V=0
14    0x2    N=1, Z=0, C=0, V=0
15    0x1    N=1, Z=0, C=0, V=0
16    0x0    N=0, Z=1, C=1, V=0
The table on the left illustrates the results that were taken for register one and the condition flags. The usq loop has been iterated 16 times, as can be seen on the table on the left hand side.

Question 3
Before executing the code Pc register had the value of 0x10E and the LR register had the value of 0XED. However, after executing the code for the second time, the PC register value changes to 0Xec. The reason for this change is because the BX instruction branches to the address that is stored in the link register. The LR register did not change the value and stayed as 0Xed.
Question 4
Register 2 stored the address of 1F after line 30 was executed. The content of R2 was then moved to register 0 which has become 1F.

READ ALSO :   Business Ethics

Week 5
Question 1
Both codes on uApprxSqt and in the main.c are very similar. However, the uApprxSqt uses a different style of code which is the pseudo code and the main.c is using assembly language code. For instance, they both assign variables in uAppxSqt its m and n on line 8 and the main.c it’s on line 19 and 20, which are MOV r1, #0x8000 and MOV r2, #0. In addition,  the add instruction on the uApprxSqt is defined as  m += n, whereas in the main.c its defined as ADD r2, r2, r1. Also, they also do multiplication instruction in uApprxSqt it uses an if statement to do it (  if (m*m > x) ) and in the main.c its defined as follows MUL r3, r2, r2.
Question 2
The purpose of line 10 is that it first starts the instruction which is the BL usqt. Then it will do the BX instruction to LR which is branching the address that will store it in the link register.
Question 3
The purpose of line 18 is that it will push the registers onto the stack at the beginning of the registers and then, they will restore using the pop at the end of the line, on line 31

Question 1
Before executing the code on line 10, register PC was holding the address value of 0XE8, and the LR address was 0x22B. Nevertheless, after the code was executed both registers had changed the address value. The new address for register PC became 0xEE. The LR register after executing the code becomes 0xEd.
Question 2
After executing the code again to the next break-point, it executes to line number 18. The sequence that was executed each time the code was ran, executed in this order; 18, 19, 20, 24, 25 and then it hit line 28.  The next sequence that was executed in order to reach line 13 went in the order of 26, 28 and 29. This sequence was executed five times and then it jumped to line 13.
Furthermore, line 11 started to use the branch fact, which was then communicating with line 22, this was passing arguments to the subroutines, which then resulted in the B return to pass result to the callers. For instance, it started the code in line 11 and executed each line until it reached the branch return code (line 22).
Question 3
Code running with the value of 2;

After repeating the same scenario but with a value of 2, lines 18,19,20,24 and 25 ran three times and then jumped to line 28.  The next step which was trying to accomplish reaching line 13, took lines 26, 28 and 29 two times to run until it jumped to line 13.

Code running with the value of 3;
When the value changed to 3 this time, lines 18,19,20,24 and 25 this time ran four times and then moved to line 28. After this step, line 26, 28 and 29 ran in a sequence of 3 times and then jumped to line 13

Code running with the value of 5;
After repeating the same scenario but with a value of 5, lines 18,19,20,24 and 25 ran six times and then jumped to line 28.  The next step which was trying to accomplish reaching line 13, took lines 26, 28 and 29 six times to run until it jumped to line 13.

Question 4
Both of the codes in the factorial and the asm-only behave and do the exact same thing.

Week 8
XBee Radio modems
After replacing the code to analogin, the potentiometer was set from 0 all the way to 1000. So, every time the potentiometer was used accordingly it changed the number, for instance, if you turn the potentiometer to the left it will decrease the number and if it was turned to the right it will increase the result.

The results after implementing the code were as follows. If the joystick was not being pressed in any sort of direction, the result will always be 0. If the joystick was being pressed upwards, the result of 1 will be displayed on the server. Number 2 would be displayed if the down joystick was pressed. 3 would be displayed if the left button is being pressed, and 4 if the down button on the joystick is being pressed. Finally, the number 5 would be displayed if the centre button is pressed on the joystick.

TAKE ADVANTAGE OF OUR PROMOTIONAL DISCOUNT DISPLAYED ON THE WEBSITE AND GET A DISCOUNT FOR YOUR PAPER NOW!