UE18EC305: Using Keil IDE (Assembly Level Programs) Cycle 1: Computer Organization Laboratory (0-0-2-1-1)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

UE18EC305: Computer Organization Laboratory (0-0-2-1-1)

Using Keil IDE (Assembly Level Programs)

CYCLE 1
1. Write an ALP to find the GCD (Greatest Common Divisor) with conditional execution of ARM
instructions.

AREA GCD, CODE, READONLY


ENTRY
MOV R0, #25
MOV R1, #5
BACK CMP R0, R1
BEQ label
BLT lessd
SUB R0, R0, R1
B BACK
lessd SUB R1, R1, R0
B BACK
Label B Label
END
Output: GCD of two numbers is 5
2. Write an ALP to copy the given string from Source to Destination
AREA strcpy, CODE, READWRITE
adr r0,source
adr r1,destination
mov r2,#8
loop1 ldrb r3,[r0],#1
strb r3,[r1],#1
subs r2,r2,#1
bne loop1
source dcb 'p','a','v','i','t','h','r','a';
destination dcb '0','0','0','0','0','0','0','0'
end
output Destination will be having the string as of source

3.Write an ALP to find the product of two matrices using with and without MLA ARM instruction.
AREA MAT3MUL, CODE, READWRITE ; name this block of code
ADR R1,ARRY1
ADR R3, RESULT
MOV R0, #3 ; ROW COUNTER
BACK ADR R2,ARRY2
MOV R4, #3 ;COLUMN COUNTER
NEXT MOV R6,#0
MOV R5,#3 ; DOT MULTIPLICATION COUNTER
X LDR R7, [R1], #4
LDR R8, [R2], #12
MLA R6, R7, R8, R6
SUBS R5, R5, #1
BNE X
STR R6, [R3], #4
SUBS R4, R4, #1
SUB R2, R2, #0X20
SUBNE R1, R1, #12
BNE NEXT
SUBS R0,R0,#1
BNE BACK
HERE B HERE
ARRY1 DCD 1,2,3
DCD 4,5,6
DCD 7,8,9
ARRY2 DCD 1,2,3
DCD 1,2,3
DCD 1,2,3
RESULT SPACE 50
END
Output:
6 0c 12

0f 1e 2d
18 30 48

4.Write an ALP to find the convolution of two sequences using with and without MLA ARM
instruction
AREA CONVOLUTION, CODE, READwrite ; name this block of code
ADR R0,SEQ1
ADR R5, RES
MOV R10, #4
MOV R9,#1
; FIRST HALF
BACK MOV R2,#0
ADR R1, SEQ2
MOV R11,R9
BL PROD
STR R2, [R5],#4
ADD R9, R9, #1
MOV R12, R9, LSL #2
ADD R0, R0, R12
SUBS R10,R10, #1
BNE BACK
; SECOND HALF
MOV R10,#3
MOV R12, #4
BACK1 ADR R1, SEQ2
ADR R0, SEQ1+12
MOV R2, #0
ADD R1, R1, R12
MOV R11, R10
BL PROD
STR R2, [R5], #4
ADD R12, R12, #4
SUBS R10, R10, #1
BNE BACK1
EXIT B EXIT
; DOT PRODUCT
PROD LDR R3,[R0],#-4
LDR R4,[R1],#4
MLA R2,R3,R4,R2
SUBS R11,R11,#1
BNE PROD
MOV PC, LR
SEQ1 DCD 1,2,3,4
SEQ2 DCD 5,6,7,8
RES SPACE 100
END
Output: 5,10,28,3c,3d,34,20
5. ALP to demonstrate ARM Thumb modes interworking.

AREA AddReg,CODE,READONLY ;Name this block of code.

ENTRY ;Mark first instruction to call.

Main

ADR r0,ThumbProg +1 ;Generate branch target address

;and set bit 0,hence arrive

;at target in Thumb state.

BX r0 ;Branch exchange to ThumbProg.

CODE16 ;Subsequent instructions are Thumb code.

ThumbProg

MOV r2,#2 ;Load r2 with value 2.

MOV r3,#3 ;Load r3 with value 3.

ADD r2,r2,r3 ;r2 =r2 +r3

ADR r0,ARMProg

BX r0

CODE32 ;Subsequent instructions are ARM code.

ARMProg

MOV r4,#4

MOV r5,#5

ADD r4,r4,r5

Stop

MOV r0,#0x18 ;

LDR r1,=0x20026 ;

SWI 0x123456:
END

You might also like