HW#5, page 2: reference is made in the exercises to a variable called
d, but there is none. Do you mean a?
Thank you for the correction:
Problem 4. Using C++ convert the following using the following values: register
unsigned char u=7, d=0xFF, b=0x01, c=0x72;
^
> Hi,
> Still on page 2 of the homework. Looking at the following exercises:
> 1) The expression d++ in the first table. Assuming this is meant to be
> variable a and not d, the value of which is 0xFF, what happens when 1
> is added? Does it become 0x00
yes.
, and the carry stays at 0? Or does it
if you use ADD then the carry is set to 1 in this case.
if you use INC then the INC instruction (as per manual) does not
touch the carry flag.
> remain at 0xFF and the carry becomes 1?
>
> 2) Does d++ mean an ADD or an ADDC?
Typically, INC is used because it does not alter the carry flag.
If you use ADDC then you must clear the carry beforehand CLR C:
Remember: ADD is the same as CLR C; ADDC
>
> 3) Similarly, does >> mean an RR or an RRC?
Well if you used RR then bit d0 gets copied into the signbit d7.
if you use RRC then bit d0 goes to the carry and the carry goes
to the signbit d7. For an unsigned shift right, zeros are shifted
into the signbit. So, that would imply using the clear carry instruction.
> In the expression u = a >> 2,
> the value of a is 0xFF. If I use RRC, do the shifting bits just
> cycle around from one end to the other and the value stays at 0xFF with
> a carry of 0, or does it become 0x5F with a carry of 1, or does it do
> something else entirely
CLR C; MOV A,#0xff; RRC A;
Cold->A->Cnew;
0->11111111->Cnew;
01111111->1;
Now, A=7fh and C=1;
(1) is to type this in a file called test1.asm
with ".org 0; start: CLR C; MOV A,#0xff; RRC A; .end",
(2) then "as31 -l test1.asm"
double check the listing, "more test1.lst"
(3) then run "java -jar j51.jar"
set the cpu type "j51.intel.P8051"
and "trace into"
>
> 4) In the last expression, s = u = x += z, I have for the 8051
> instructions:
> MOV A,R6; ADD A,R7; MOV R0,A; MOV R4,R0;
> My question is about the last statement here. Can I do a MOV Rn,Rm?i
you cannot directly but the 8051 has enough primative instructions
to "finds a way".
s = u = x += z; precedence ==> (s = (u = (x += z)));
The RegA is your basic temp register. So, in reality it will
never be used for an application variable.
Do inner most parenthesis first.
MOV A, R6
ADD A, R7
MOV R6,A ;x += z
MOV R4,A ;s = u
> 5) Could you explain again what OV means? My understanding is that it
> is (Cin of the MSB) XOR (Cout of the MSB).
Correct:
For 8-bit number: OV = Cout of d7 XOR Cin of d7.
For 16-bit number: OV = Cout of d15 XOR Cin of d15.
> If so, I'd like to confirm
> that I understand this correctly and that there is an OV of 1 in the
> last expression, s = u = x += z; Is this right?
On the Homework 4 sheet on the last page, I copied what commands
altered the flags. MOV does not change any flag. So, The OV flag
will be the last add operation done.
>
> 6) Finally, in the second table, when doing an ADDC, does the carry
> have a value of 0x01? In other words, when performing the command ADDC
> A,R2 with A = 0x42 and R2 = 0xCE, is the result 0x42 + 0xCE + 0x01 =
> 0x50 with a CY of 1, an AC of 1 and an OV of 0 (since Cin and Cout of
> the MSB were both 1)?
Bit Sum = a XOR b XOR c;
Bit C = majority(a, b, c);
1 = Cin
1 = Cout
1 = AC
0100 0010 = 0x42
1100 1110 = 0xce
1 = C
---------
0001 0001 = 0x11
OV = Cout XOR Cin = 1 XOR 1 = 0
Now, "double check" your work by
--------------------------------
1) Typing this program in a file called test2.asm.
2) Assemble the source code: as31 -l test2.asm
3) Read the output listing: more test2.lst
4) Running the simulator: java -jar j51.jar
5) Trace through each instruction to confirm the result.
Page 82 of 80C51 programmer's guide
PSW = d7 d6 d5 d4 d3 d2 d1 d0
C AC OV
You will need to read the PSW and map the bits back to their flags:
For example: PSW = 0x80 => C=1 AC=0 OV=0
Thank you for your questions. --Prof. Wolff.
"double check your work"