Sem 6‎ > ‎MPRC LAB‎ > ‎

P1: 8085 Program to add/subtract two 8 bit numbers.

posted Mar 29, 2013, 4:55 AM by Neil Mathew   [ updated Mar 29, 2013, 5:59 AM by Neil Mathew ]

ALGO TO ADD:

Memory Address  Opcode  Mneumonics Comments
 2500 3A  LDA 2000H 3A = Load Address to Accumulator
 2501 00 LSB First (00 of 2000)
 2502 20 MSB Second (20 of 2000)
 2503 47 MOV B,A
 2504 3A LDA 2001H
 2505 01
 2506 20
 2507 80 ADD B
 2508 32 STA 2002H Stores accumulator value
 2509 02 LSB (02)
 250A 20 MSB(20)
 250B 76 HLT Halt (End of Program)


ALGO TO SUBTRACT:


Memory Address Opcode MneumonicsComments
 25003A LDA 2000H3A = Load Address to Accumulator
 250100LSB First (00 of 2000)
 250220MSB Second (20 of 2000)
 250347MOV B,A
 25043ALDA 2001H
 250501
 250620
 250790SUB BReg A(@2001) - Reg B (@2000)
 250832STA 2002HStores accumulator value
 250902LSB (02)
 250A20MSB(20)
 250B76HLTHalt (End of Program)






OUTPUT: (ADD)

    2000    01
    2001    04

    After execution of program:

    2003    05


OUTPUT: (SUB)

    2000    01
    2001    04

    After execution of program:

    2003    03

Note the first number is stored at Reg B and the second one into Accumulator. Hence, when the SUB B command is executed, the first number is subtracted FROM the second number.



The memory address states the location where we are entering the hexadecimal Opcode. After this, we supply the two inputs (to add) at 2000H and 2001H. (Say, 01 is entered at 2000H and maybe 04 is entered at 2001H). The location of the start of the program would be at 2500H)

Execute the program at 2500H.

And on execution, check the value at location 2002H. (Answer should be 05).

Hexadecimal addition even allows the following:

0 B    ( 0 11)
1 3    ( 1  03)
___

1 E


Comments