0% found this document useful (0 votes)
78 views6 pages

Flowchart Prog Exercise2

The document describes several programming exercises involving arithmetic and logic operations including addition, subtraction, multiplication, division, and generating even parity. It provides the logic flow and instructions for performing each operation by loading operands from memory, performing the operation, and storing the result back in memory. Examples are given for each operation to illustrate the process.

Uploaded by

Peter Go
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views6 pages

Flowchart Prog Exercise2

The document describes several programming exercises involving arithmetic and logic operations including addition, subtraction, multiplication, division, and generating even parity. It provides the logic flow and instructions for performing each operation by loading operands from memory, performing the operation, and storing the result back in memory. Examples are given for each operation to illustrate the process.

Uploaded by

Peter Go
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Programming Exercise 2

1. a) Addition

4100 Operand 1 A Operand 1


+
4101 Operand 2
B Operand 1

4200 Result A Result

4201 Carry
C Carry

Initialize counter (for carry).


Set pointer to data (operand
1 & operand 2) in memory. LXI H,4100H
Set pointer to storage of data LXI D,4200H
in memory. MVI C,00H

MOV A,M
Load operand 1 into [A]. INX H
Load operand 2 into [B]. MOV B,M

Add [B] to [A]. ADD B

NO JNC SKIP
Any carry?

YES

INR C Increment counter.

SKIP: STAX D
Store results in INX D
End.
memory. MOV A,C
STAX D
RST 1
b) Subtraction

4100 Operand 1 A Operand 1


-
4101 Operand 2
B Operand 1

4200 Result A Result

4201 Carry
C Borrow

Initialize counter (for carry).


Set pointer to data (operand
1 & operand 2) in memory. LXI H,4100H
Set pointer to storage of data LXI D,4200H
in memory. MVI C,00H

MOV A,M
Load operand 1 into [A]. INX H
Load operand 2 into [B]. MOV B,M

Subtract [B] from [A]. SUB B

NO JNC SKIP
Any borrow?

YES

INR C Increment counter.

SKIP: STAX D
Store results in INX D
End.
memory. MOV A,C
STAX D
RST 1
c) Multiplication

4100 Operand 1 A 00H


+
4101 Operand 2
B Operand 1
(Operand 2)
times

4200 Result A Result (Low)


Carry
4201 Carry
E Result (High)

Initialize counter (for carry).


Set pointer to data (operand LXI H,4100H
1 & operand 2) in memory. MVI E,00H

MOV B,M
Load operand 1 (multiplicand) into [B]. INX H
Load operand 2 (multiplier) into [C]. MOV C,M

Clear [A]. XRA A

Add [B] to [A]. REPEAT: ADD B

NO JNC SKIP
Any carry?

YES

Increment counter. INR E

Decrement multiplier. SKIP: DCR C

JNZ REPEAT
Multiplier = 0?

NO
LXI H,4200H
YES MOV M,A
INX H
Store results in memory. End. MOV M,E
RST 1
d) Division

4100 Operand 1 A Operand 1


-
4101 Operand 2
B Operand 2
Until
operand 1 <
operand 2
4200 Result A Remainder
Number of
4201 Carry subtractions
E Quotient

Initialize counter (for quotient). LXI H,4100H


Set pointer to data (operand 1 MVI E,00H
& operand 2) in memory.

MOV A,M
Load operand 1 (dividend) into [A]. INX H
Load operand 2 (divisor) into [B]. MOV B,M

Compare [A] with [B]. CMP B

YES JC STORE
[A] < [B]?

NO

Subtract [B] from [A]. REPEAT: SUB B

Increment counter. INR E

Compare [A] with [B]. CMP B

NO JNC REPEAT
[A] < [B]?

YES

Store results ([A] – STORE: LXI H,4200H


remainder, [E] - quotient) MOV M,E
in memory. INX H
MOV M,A
RST 1
End.
4. Even parity generator at the transmitting end

Input: ASCII character (7 bit)


Output: parity bit (1 bit) + ASCII character (7bit) = 8 bit character

Process:
Checks input for even parity. If the input has even parity, parity bit = 0. If
input has odd parity, parity bit = 1. The parity bit is the MSB of the 8 bit
output.

Example:
Input: R = 52H = 101 0010B (odd parity)
Output: 1101 0010B (even parity)

Input: A = 41H = 100 0001 (even parity)


Output: 0100 0001 (even parity)

Set counter.
Set pointer to LXI H, 5000H
data in memory MVI C, count

NEXTCHAR: MOV B,M


Load data into [A]. XRA A
ADD B

Check if data has


even parity.
JPE SKIP

NO
Even parity? Insert ‘1’ at MSB.
Transfer value back.

YES
ADI 80H
MOV M,A
Set pointer to next
SKIP: INX H data.

Decrement counter. DCR C


JNZ NXTCHAR

NO YES
Counter = 0?
End. RST 1
Even parity checker at the receiving end

Input: Output from the even parity generator (8 bit)


Output: Store ‘ACK’ if there is no error, else store ‘NACK’

Process:
Check each data to confirm that it has even parity. If all data has even parity,
store ‘ACK’. If any one of the data has odd parity, an error has occurred and
‘NAK’ is stored.

Set counter. LXI H, 5000H


Set pointer to MVI C, count
data in memory

NXTCHECK: MOV B,M


Load data into [A]. XRA A
ADD B

Check if data has


odd parity. JPO ERROR

YES
Odd parity? Store ‘NAK’

NO ERROR: MVI A,NAK


STA 8800H

Set pointer to next


SKIP: INX H data.

DCR C
Decrement counter. JNZ NXTCHECK

NO YES
Counter = 0? Store ‘ACK’

MVI A,ACK
STA 8800H

End. RST 1

You might also like