Sei sulla pagina 1di 3

3

EXP NO: 01
DATE:



ADDITION OF 8 BIT AND 16 BIT
AIM



PROGRAMS
;************ Program description
;8 bit unsigned addition using register addressing
;R2 NUM1; R3 NUM2
;R4 LSB, R5 MSB
;************ Constants
;************ variable declaration

ORG 0x0000
LJMP START

ORG 0X0040
START: CLR A
MOV R4,A ;clear result vars
MOV R2,#20
MOV R3,#30 ;LOAD VALUES IN REGISTER

MOV A,R2
ADD A,R3
JNC NOOFLOW
INC R5
NOOFLOW: MOV R4,A
SJMP $ ;Control stays here
END









4
PROGRAMS
;************ Program description
;8 bit unsigned addition using register addressing
;R2 NUM1; R3 NUM2
;R4 LSB, R5 MSB
;************ Constants
;************ variable declaration

ORG 0x0000
LJMP START
ORG 0X0040

START: CLR A
MOV R4,A ;CLEAR RESULT
MOV R2,#20
MOV R3,#30 ;LOAD VALUES IN REGISTER

MOV A,R2
ADD A,R3
JNC NOOFLOW
INC R5
NOOFLOW: MOV R4,A


SJMP $ ;CONTROL STAYS HERE
END


;************ Program description
;16 bit Add

;************ Constants
;************ variable declaration
ORG 0x0000
LJMP START
ORG 0X0040
START:
MOV R6,#1Ah ;Load the Iirst value into R6 and R7
MOV R7,#44h ;Load the second value into R4 and R5
MOV R4,#22h
MOV R5,#0DBh
LCALL ADD1616 ;Call the 16-bit addition routine
SJMP $ ;Control stays here

5


ADD1616:
;Step 1 oI the process

MOV A,R7 ;Move the low-byte into the
accumulator
ADD A,R5 ;Add the second low-byte to the
accumulator
MOV R3,A
;Move the answer to the low-byte oI the result
;Step 2 oI the process

MOV A,R6 ;Move the high-byte into the accumulator
ADDC A,R4 ;Add the second high-
byte `to the accumulator, plus carry.
MOV R2,A ;Move the answer to the high-byte oI the result
;Step 3 oI the process

MOV A,#00h ;By deIault, the highest byte will be zero.
ADDC A,#00h ;Add zero, plus carry Irom step 2.
MOV R1,A ;Move the answer to the highest byte oI the
result
RET ;Return - answer now resides in R1, R2, and R3.
END




RESULT





6
EXP NO: 02
DATE:



SUBTRACTION OF 8 BIT AND 16 BIT
AIM




PROGRAMS
;************ Program description
;8 bit unsigned addition using register addressing
;R2 NUM1; R3 NUM2
;R4 LSB, R5 MSB
;************ Constants
;************ variable declaration

ORG 0x0000
LJMP START

ORG 0X0040
START: CLR A
MOV R4,A ;clear result vars
MOV R2,#20
MOV R3,#30 ;LOAD VALUES IN REGISTER

MOV A,R2
SUBB A,R3
JNC NOOFLOW
INC R5
NOOFLOW: MOV R4,A
SJMP $ ;Control stays here
END


************ Program description
;16 bit SUB
;************ Constants
;************ variable declaration
ORG 0x0000
LJMP START
ORG 0X0040
START:

7


MOV R6,#22h ;Load the Iirst value into R6 and R7
MOV R7,#0DBh ;Load the second value into R4 and R5
MOV R4,#1Ah
MOV R5,#0F9h
LCALL SUBB1616 ;Call the 16-bit SUb routine
SJMP $ ;Control stays here


SUBB1616:
;Step 1 oI the process
MOV A,R7 ;Move the low-byte into the accumulator
CLR C ;Always clear carry beIore Iirst subtraction
SUBB
;Subtract the second low-byte Irom the
accumulator
MOV R3,A ;Move the answer to the low-byte oI the result

;Step 2 oI the process
MOV A,R6 ;Move the high-byte into the accumulator
SUBB A,R4 ;Subtract the second high-byte Irom the
accumulator
MOV R2,A ;Move the answer to the low-byte oI the result
RET ;Return - answer now resides in R2, and R3.
END



RESULT

8
EXP NO: 03
DATE:



MULTIPLICATION OF 16 BIT
AIM



PROGRAMS
*********** Program description
;16 bit Multiplication
;************ Constants
;************ variable declaration
ORG 0x0000
LJMP START
ORG 0X0040
START:
MOV R6,#62h ;Load the Iirst value into R6 and R7
MOV R7,#30h
MOV R4,#43h ;Load the Iirst value into R4 and R5
MOV R5,#2Eh
LCALL MUL1616 ;Call the 16-bit subtraction routine
SJMP $
MUL1616:
;Multiply R5 by R7
MOV A,R5 ;Move the R5 into the Accumulator
MOV B,R7 ; Move R7 into B
MUL AB ;Multiply the two values
MOV R2,B ; Move B (the high-byte) into R2
MOV R3,A ;Move A (the low-byte) into R3

;Multiply R5 by R6
MOV A,R5 ;Move R5 back into the Accumulator
MOV B,R6 ;Move R6 into B
MUL AB ;Multiply the two values
ADD A,R2 ;Add the low-byte into the value already in
R2
MOV R2,A ;Move the resulting value back into R2
MOV A,B ;Move the high-byte into the accumulator
ADDC A,#00h ;Add zero (plus the carry, iI any)
MOV R1,A ;Move the resulting answer into R1
MOV A,#00h ;Load the accumulator with zero
ADDC A,#00h ;Add zero (plus the carry, iI any)

9
MOV R0,A ;Move the resulting answer to R0.
;Multiply R4 by R7
MOV A,R4 ;Move R4 into the Accumulator
MOV B,R7 ;Move R7 into B
MUL AB Multiply the two values
ADD A,R2
;Add the low-byte into the value already in
R2
MOV R2,A ; Move the resulting value back into R2
MOV A,B ;Move the high-byte into the
accumulator
ADDC A,R1
;Add the current value oI R1 (plus any carry)
MOV R1,A ;Move the resulting answer into R1.
MOV A,#00h ;Load the accumulator with zero
ADDC A,R0
;Add the current value oI R0 (plus anycarry)
MOV R0,A ; Move the resulting answer to R1.
;Multiply R4 by R6

MOV A,R4 ;Move R4 back into the Accumulator
MOV B,R6 ;Move R6 into B
MUL AB ;Multiply the two values
ADD A,R1
Add the low-byte into the value already in R1
MOV R1,A ;Move the resulting value back into R1
MOV A,B ;Move the high-byte into the
accumulator
ADDC A,R0
;Add it to the value already in R0 (plus any carry)
MOV R0,A ; Move the resulting answer back to R0
RET ;Return - answer is now in R0, R1, R2,
and
R3
END;


RESULT



10
EXP NO: 04
DATE:



DIVISION OF 8 BIT
AIM



PROGRAMS

;************ Program description
;8 bit Division using register addressing
;R2 NUM1; R3 NUM2
;R4 LSB, R5 MSB
;************ Constants
;************ variable declaration

ORG 0x0000
LJMP START
ORG 0X0040

START:
MOV R2,#4
MOV R3,#2
MOV A,R3
MOV R4,A ;LOAD VALUES IN REGISTER
MOV A,R2
LOOP2:
SUBB A,R3
JC LOOP1
INC R5
DJNZ R4, LOOP2
SJMP LOOP3
LOOP1: INC R5
LOOP3: MOV R6,A
SJMP $ ;Control stays here
END

RESULT

11
EXP NO: 05
DATE:

SMALLEST AND LARGEST NUMBER
AIM


PROGRAM
;************ Program description
;8 bit unsigned addition of series of numbers using indirect addressing
;INPUT LOCATION 41 to 4F,40 -number oI digits, OUTPUT LOCATION 50 & 51
;;************ Constants
Input EQU 0x40
Result EQU 0x50
Big EQU 0x30
;************ variable declaration

ORG 0x0000
LJMP START

ORG 0X0040

START: MOV A,#0
MOV Big,A ;INITIALISE TEMP VARIABLES

MOV R0,#Input ;INITIALISE POINTERS
MOV R1,#Result

ACALL InitInputs ;INITIALISE MEMORY LOCATION

MOV A,R0 ;INITIALISE COUNTER, R2 IS USED AS COUNTER
MOV R2,A
INC R0

CLR C
CHKAGAIN: MOV A,R0
SUBB A,Big
JC OOFLOW
MOV Big,R0 ;Small A, iI carry occurs
OOFLOW: INC R0
DJNZ R2,CHKAGAIN

MOV R1,Big ;STORE LSB IN RESULT LOCATION

12

SJMP $ ;Control stays here

;FUNCTION TO LOAD VALUE AT MEMORY LOCATION
InitInputs: MOV R0,#8 ;8 numbers to be processed
MOV A,R0 ;INITIALISE COUNTER
MOV R2,A
INC R0

MOV A,#20
DOAGAIN: MOV R0,A ;LOAD 20,21... IN TO MEMORY LOCATION
INC A
INC R0
DJNZ R2,DOAGAIN
MOV R0,#Input ;INITIALISE POINTERS
RET
END












RESULT





13
EXP NO: 06
DATE:

COUNT THE NUMBER OF EVEN AND ODD NUMBERS
AIM


PROGRAM
;************ Program description
;8 bit unsigned addition oI series oI numbers using indirect addressing
;INPUT LOCATION 41 to 4F,40 -number oI digits, OUTPUT LOCATION 50 & 51
;50 - even numbers, 51 - oddnumbers
;R3 - even numbers,R4 - odd nubers
;************ Constants
Input EQU 0x40
Result EQU 0x50
EvenNum EQU 0x30
OddNum EQU 0x31
;************ variable declaration

ORG 0x0000
LJMP START
ORG 0X0040

START:
MOV A,#0
MOV EvenNum,A ;INITIALISE TEMP REGISTERS
MOV OddNum,A
MOV R0,#Input ;INITIALISE POINTERS
MOV R1,#Result
ACALL InitInputs ;INITIALISE MEMORY LOCATION
MOV A,R0 ;INITIALISE COUNTER, R2 IS USED AS COUNTER
MOV R2,A
INC R0
CLR C
CHKAGAIN:
MOV A,R0
RRC A
JNC EVEN
INC OddNum ;ODD COUNT INCREMENTED
SJMP AGAIN
EVEN: INC EvenNum ;EVEN COUNT INCREMENTED
AGAIN: INC R0
DJNZ R2 ,CHKAGAIN

14

MOV R1,EvenNum ;STORE LSB IN RESULT LOCATION
INC R1
MOV R1,OddNum ;STORE LSB IN RESULT LOCATION


SJMP $ ;Control stays here



;************ FUNCTION TO LOAD VALUE AT MEMORY LOCATION
**********************
InitInputs: MOV R0,#8 ;8 numbers to be processed
MOV A,R0 ;INITIALISE COUNTER
MOV R2,A
INC R0
MOV A,#20
DOAGAIN: MOV R0,A ;LOAD 20,21... IN TO MEMORY LOCATION
INC A
INC R0
DJNZ R2,DOAGAIN
MOV R0,#Input ;INITIALISE POINTERS
RET
END






RESULT





15
EXP NO:07
DATE:

TO FIND THE POSITIVE AND NEGATIVE NUMBER
AIM



PROGRAM
;************ Program description
;CHECKS THE GIVEN NUMBER IS ODD OR EVEN using indirect addressing
;INPUT LOCATION 40,OUTPUT LOCATION 41 0, iI POSITIVE else 41 1
;************ Constants
Input EQU 0x40
;************ variable declaration
ORG 0x0000
LJMP START
ORG 0X0040
START:
MOV R0,#Input ;INITIALISE POINTERS

MOV R0,#31 ;LOAD DATA IN MEMORY

CLR C
MOV A,R0
INC R0
RLC A
JC NEGATIVE
MOV R0,#0 ;NUMBER IS POSITIVE
SJMP DONE
NEGATIVE: MOV R0,#1 ;NUMBER IS NEGATIVE

DONE: SJMP $ ;Control stays here
END

RESULT



16
EXP NO:08
DATE:

SORTING OF NUMBER
AIM


PROGRAM
ASCENDING
ORG 00h
;-----------------------------------Data Required Ior the Program------------------------------------
MOV R4,#04h ;Counter Ior LOOP1
MOV 50h,#0x05
MOV 51h,#0x03
MOV 52h,#0x02
MOV 53h,#0x04
;----------------------------Sort in Ascending Order Using Bubble Sort-------------------------------
LOOP1: ;Outer Loop - Handles number oI passes
MOV R0, #03h
MOV R1,#50h ;Point to beginning oI array
MOV A, R0 ;Initialize R0 - the counter Ior LOOP2
MOV R3, A ;to the value oI R0 -
the number oI iterations in each pass is same
;as the number oI elements minus serial
number oI the current pass.
LOOP2: ;Inner Loop - Handles each pass.
MOV A, R1 ;Copy a number oI the array to the accumulator
MOV R3, A ;and store it in R3.
INC R1 ;Move to the net number
MOV A, R1 ;and store that in the accumulator.

SUBB A, R3 ;Subtract the Iirst Irom the second.

JNC Continue2 ;II no carry is generated the
second is greater and the numbers are ;in order with
respect to each other. Otherwise they must be swapped.
MOV A, R1 ;Move the second number to the accumulator.
XCH A, R3 ;Exchange contents oI
the accumulator and R3. This makes A contain the Iirst
number and R1 the second.
MOV R1, A ;Store the Iirst
number at the place where the second one was stored.
DEC R1 ;Move to the previous memory location.
MOV A, R3 ;Copy the second number to the accumulator

17
MOV R1, A ;and store it in the Iirst number's place.
INC R1 ;Move to the next memory location.

Continue2:
DJNZ R0, LOOP2 ;Move on to the next iteration oI the current pass.

Continue1:
DJNZ R4, LOOP1 ;Move on to the next pass.

Here: SJMP Here ;End oI program - Loop here indeIinitely.
END
;----------------------------------------------------------------------------------------------------

DESENDING

;----------------------------------------------------------------------------------------------------
ORG 00h
;-----------------------------------Data Required Ior the Program------------------------------------
MOV R4,#04h ;Counter Ior LOOP1
MOV 50h,#0x02
MOV 51h,#0x04
MOV 52h,#0x03
MOV 53h,#0x05
;----------------------------Sort in Desending Order Using Bubble Sort-------------------------------
LOOP1: ;Outer Loop - Handles number oI passes
MOV R0, #03h
MOV R1,#50h ;Point to beginning oI array
MOV A, R0 ;Initialize R1 - the counter Ior LOOP2
MOV R3, A ;to the value oI R0 -
the number oI iterations in each pass is same
as the number oI elements minus serial
number oI the current pass.
LOOP2: ;Inner Loop - Handles each pass.
MOV A, R1 ;Copy a number oI the array to the accumulator
MOV R3, A ;and store it in R2.
INC R1 ;Move to the net number
MOV A, R1 ;and store that in the accumulator.
SUBB A, R3 ;Subtract the Iirst Irom the second.
JC Continue2
;II no carry is generated the second is greater and
the numbers are
in order with respect to each other.
Otherwise they must be swapped.
MOV A, R1 ;Move the second number to the accumulator.

18
XCH A, R3
;Exchange contents oI the accumulator and R2.
This makes A contain the Iirst number and R2 the second.
MOV R1, A ;Store the Iirst number
at the place where the second one was stored.
DEC R1 ;Move to the previous memory location.
MOV A, R3 ;Copy the second number to the accumulator
MOV R1, A ;and store it in the Iirst number's place.
INC R1 ;Move to the next memory location.

Continue2:
DJNZ R0, LOOP2 ;Move on to the next iteration oI the current pass.

Continue1:
DJNZ R4, LOOP1 ;Move on to the next pass.

Here:
SJMP Here ;End oI program - Loop here indeIinitely.
END






RESULT

Potrebbero piacerti anche