Professional Documents
Culture Documents
CCE 320-Mohamad Hamza-HW2
CCE 320-Mohamad Hamza-HW2
Question #1:
After executing the following code:
MOVLW FFH
ADDLW 1
The status of the C (carry) and Z (zero) flags depend on the execution result of the
ADDLW instruction.
The ADDLW instruction adds the literal value 1 to the contents of the W register,
and updates the C and Z flags based on the result.
In this case, the W register contains FFH before the addition, and adding 1 to it
results in the value 00H, with a carry out.
Therefore, the C flag is set to 1 (indicating a carry-out), and the Z flag is cleared to
0 (since the result is not zero).
So, the status of the C and Z flags after the execution of the code are:
C = 1/Z = 0
Question #2:
a) MOVLW 45H ADDLW 0C4H:
• The MOVLW 45H instruction loads the value 45H into the WREG register.
• The ADDLW 0C4H instruction adds the literal value C4H to the value in the
WREG register.
• The result is 09H, which is stored back in the WREG register.
• There is no carry from the addition, so the C flag is cleared.
Therefore, the value of the C flag is 0 for this code.
b) MOVLW 00 ADDLW FFH:
• The MOVLW 00 instruction loads the value 00 into the WREG register.
• The ADDLW FFH instruction adds the literal value FFH to the value in the
WREG register.
• The result is FFH, which is stored back in the WREG register.
• There is a carry from the addition, so the C flag is set.
Therefore, the value of the C flag is 1 for this code.
c) MOVLW FFH ADDLW 05H:
• The MOVLW FFH instruction loads the value FFH into the WREG register.
• The ADDLW 05H instruction adds the literal value 05H to the value in the
WREG register.
• The result is 04H, which is stored back in the WREG register.
• There is a carry from the addition, so the C flag is set.
Therefore, the value of the C flag is 1 for this code.
Question #3:
ORG 0x0000 ; start at program memory address 0x0000
loop:
ADDWF temp, F ; add the value in temp to itself (in place)
DECFSZ counter, F ; decrement the counter and skip next instruction if zero
GOTO loop ; jump back to the loop label if counter is not zero