Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

;* Arithmatic_Logical_Instruction.

asm : This program is for the


demonstration of Arithmatic and Logical Instructions.
;* Created: 18/07/2020 10:59:00 PM
;* Author: Uday B.Mujumdar,Department of Electrical
Engineering,RCOEM,Nagpur mujumdarub@rknec.edu
;*********************************************************************
****************************************************************
.def Temp0 = R0 ; Define Register R0 as Temparary
Register identified as Temp1
.def Temp1 = R16 ; R16 is defined as Temporary storage
as Temp2
.include "m32Adef.inc" ; Inclusion of this file includes all
the Registers,Ports,Peripherals andmemories of Mega32.
.cseg ; CODE segment
.org 0 ; Specifies the
starting address of Flash memory
jmp Start
;1 $000(1) RESET External Pin, Power-on Reset, Brown-out
;*********************************************************************
****************************************************************
; Stack Pointer Initialisation: Initialise the stack pointer with Top
of Static data memory
;*********************************************************************
****************************************************************
Start:
ldi Temp1,high(RAMEND) ; Initialsie
Temp1 with Top address-High byte of Data Ram as stack memory
out SPH,Temp1 ; Store in
Stack Pointer high
ldi Temp1,low(RAMEND)
; Initialsie Temp1 with Top address-Low byte of Data Ram
out SPL,Temp1
; Store in Stack Pointer high
;*********************************************************************
****************************************************************
; 1. Arithmatic Operation :
;*********************************************************************
****************************************************************
; Addition of two data bytes: Verify: i) Status register, ii)
Respective Registers
add_demo_00:
ldi R16,$56
ldi R17,$67
add R16,R17
; R16= (R16+R17)
; Substraction of two 8 bit data bytes i) Status register, ii)
Respective Registers
sub_demo_00:
ldi R21,$DA
ldi R20,$34
sub R21,R20
; R21=(R21-R20) --> Register substraction
subi R21,$29
; R21=(R21-$29) --> Immediate substraction
; Increment and decrement a Register by 1
Inc_Dec_demo_00:
ldi R16,01
; R16=1
inc R16
; R16=R16+1 =2
inc R16
; R16=R16+1 =3
dec R16
; R16=R16-1 =2
; Multiplication of two numbers: $CD*$FC= $C9CC ( Result $C9 is MSB
in R1 and $CC in R0)
Mul_demo_00:
ldi R16,$CD
ldi R17,$FC
mul R16,R17
; Multiplication is over, check the result in R1:Ro
;*********************************************************************
****************************************************************
; 2. Logical Operation:
;*********************************************************************
***************************************************************
and_demo_00:
; AND operation
ldi R23,0b10101010
; R23= 0b10101010
ldi R24,0b10010110
; R24= 0b10010110
and R23,R24
; R23=(R21.R24) --> Register anding
andi R23,0b11110000
; R23=(R23.0b11110000) --> Immediate anding

or_demo_00:
; OR Operation
ldi R23,0b10101010
; R23= 0b10101010
ldi R24,0b10010110
; R24= 0b10010110
or R23,R24
; R23=(R21 or R24) --> Register oring
ori R23,0b11110000
; R23=(R23 or 0b11110000) --> Immediate oring

eor_demo_00:
; EXOR Operation
ldi R23,0b10101010
; R23= 0b10101010
ldi R24,0b10010110
; R24= 0b10010110
eor R23,R24
; R23=(R21 exor R24) --> Register oring

clr_ser_com_demo:
; Clear and Set Register,
ldi R16,$AA
; load a byte
clr R16
; R16 = 00
ser R16
; R16 = $FF
com R16
; Get ones compliment
;*********************************************************************
****************************************************************

You might also like