0% found this document useful (0 votes)
18 views19 pages

Tabrez Coa 1

The document contains a series of programming assignments for a Computer Organization and Architecture course at Dayananda Sagar University. Each assignment includes ARM assembly code to perform various tasks such as setting bits in a register, converting characters to uppercase, counting bits, sorting numbers, and checking for palindromes. The assignments are structured with questions, code snippets, and expected outputs.

Uploaded by

girishsanam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views19 pages

Tabrez Coa 1

The document contains a series of programming assignments for a Computer Organization and Architecture course at Dayananda Sagar University. Each assignment includes ARM assembly code to perform various tasks such as setting bits in a register, converting characters to uppercase, counting bits, sorting numbers, and checking for palindromes. The assignments are structured with questions, code snippets, and expected outputs.

Uploaded by

girishsanam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Dayananda Sagar University

School of Engineering

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

Computer Organization and Architecture


Course Code: 23CS2405

Assignment 1

Name: SHAIK TABREZ AHAMAD

USN: ENG23CS0451

Section: G

Semester: 4th
Assignment No: 1

Date: 21-05-2025

Question & Answers


Q.1 Write ARM instructions that set bits 0, 4, and 12 in register r6
and leave the remaining bits unchanged

</> Code
AREA RESET, CODE, READONLY
ENTRY
EXPORT __main

__main
MOV R6, #0x00000000

MOV R1, #(1 << 0)


ORR R6, R6, R1

MOV R1, #(1 << 4)


ORR R6, R6, R1

MOV R1, #(1 << 12)


ORR R6, R6, R1

loop B loop
END
OutPut
Q.2

Write a program that takes character data “a” through “z” and
returns the character in uppercase.

</> Code

AREA RESET, CODE, READONLY


ENTRY
EXPORT __main

__main
MOV R1, #'a'

SUB R2, R1, #0x20

loop B loop
END

OutPut
C\Users\dewi\OneDrive\Documents\CoA Assignments\Coa.uvproj - µVision4

File Edit View Project Flash Debug Peripherals Tools SVCS Window Help

0 0 =

Registers Disassembly
8:
Register Value
9: Subtract 0x20 to convert to uppercase
Current
0x00000000 E3A01061 MOV R1,#0x00000061
RO 0x00000000
10: SUB R2, R1, #0x20 : R2- Rl 0x20 ? should be Ox41 ('A')
R1 0x00000061
11:
R2 0x00000041
0x00000004 E2412020 SUB R2, R1, #0x00000020
R3 0x00000000
12: loop B 10op
R4 0x00000000
0x00000008 EAFFFFFE B 0x00000008
R5 0x00000000
0x00000000 00000000 ANDEO RO.RO.RO
R6
R7 0x00000000
R8 0x00000000
00000000%0 main.s
R9
AREA RESET, CODE, READONLY
R10 0x00000000
ENTRY
R11 0x00000000
EXPORT main
R12 0x00000000
R13 (SP) 0x00000000
00000000*0 main
R14 (LR)
Let's assume Rl has lowercase character 'a' 0x61
R15 (PC) 0x00000008
MOV Rl, #'a RI- 0x61

7890)
:
CPSR 0x00000003
00000000*0
F SPSR
Subtract 0x20 to convert to uppercase
User/System SUB R2, R1. #0x20 R2 R1- 0x20 ? should be 0x41 ('A')
Fast Interrupt
Intermrupt
12 loop B 1oop
Supervisor END
13
Abort 14
Undefined
Ε Intemal
PC $ 0x00000008

Project Registers

Command Call Stack + Locals

Running with Code Size Limit: 32K Location/Value


Name Type
Load "C:\\Users\\devvi\\OneDrive\\Documents\\CoA Assignments\\Coa.AXF"
_asm_0x0 0x00000000 void f0

Restricted Version with 32768 Byte Code Size Limit


** Currently used: 12 Bytes (0%)

ASSIGN BreakDisable BreakEnable BreakKill BreakList BreakSet BreakAccess COVERAGE DEFINE DIR Call Stack + Locals Memory 1

Real-Time Agent: Target Stopped Simulation t1: 22.65265467 sec L:12 C:1 CAP NUM SCRL OVR
Q.4
Write a program to count the number of ones and zeros in two
consecutive memory locations.
</> Code
AREA RESET, CODE, READONLY
ENTRY
EXPORT __main

__main
MOV R0, #0xF0
ORR R0, R0, R0, LSL #8
ORR R0, R0, R0, LSL #16

MOV R1, #0
MOV R2, #0
MOV R3, #32

check_bit
TST R0, #1
ADDNE R1, R1, #1
ADDEQ R2, R2, #1
LSR R0, R0, #1
SUBS R3, R3, #1
BNE check_bit

loop B loop
END
OutPut
Write a program to arrange a series of 32-bit number in
ascending and descending order.

</>Code
Q.6

AREA RESET, CODE, READONLY


ENTRY
EXPORT __main

__main
LDR R0, =array MOV R1, #5

sort_outer
MOV R2, #0

sort_inner
CMP R2, R1 BGE sort_done

LDR R3, [R0, R2, LSL #2]


ADD R4, R2, #1
LDR R5, [R0, R4, LSL #2]
CMP R3, R5 BLE skip_swap

; Swap array[i] and array[i+1]


STR R5, [R0, R2, LSL #2]
STR R3, [R0, R4, LSL #2]

skip_swap
ADD R2, R2, #1
SUB R6, R1, #1
CMP R2, R6 BLT sort_inner

SUB R1, R1, #1


B sort_outer
sort_done
B sort_done
AREA data, DATA, READWRITE
array DCD 45, 11, 23, 90, 3
END

OutPut
Q.5 Write a program to find the largest and smallest number in an array
of 32 numbers.

</> Code
AREA RESET, CODE, READONLY
ENTRY
EXPORT __main

__main
LDR R0, =array MOV R1, #5

LDR R3, [R0]


LDR R4, [R0] MOV R2, #1

loop
CMP R2, R1 BGE done

LDR R5, [R0, R2, LSL #2]

CMP R5, R3
BLS check_min
MOV R3, R5

check_min
CMP R5, R4
BGE next
MOV R4, R5 next
ADD R2, R2, #1
B loop

done
B done
AREA data, DATA, READWRITE
array DCD 45, 11, 23, 90, 3
END

OutPut

Q.6 Write a program to add an array of 16-bit numbers and store the
32bit result in internal RAM.

</> Code
AREA RESET, CODE, READONLY
ENTRY
EXPORT __main

__main
LDR R0, =array
MOV R1, #5
MOV R2, #0 MOV R3, #0

loop
CMP R3, R1 BGE done

ADD R6, R3, R3


LDRH R4, [R0, R6]
ADD R2, R2, R4
ADD R3, R3, #1
B loop

done
LDR R5, =result STR R2, [R5]

B done

AREA data, DATA, READWRITE


array DCW 100, 200, 300, 400, 500
result DCD 0
END

OutPut
Q.7 Write a program to search a key element in a list of ‘n’ elements.
</> Code
AREA RESET, CODE, READONLY
ENTRY
EXPORT __main

__main
LDR R0, =array
MOV R1, #6
LDR R2, =key
LDR R3, [R2]
MOV R4, #0 MOV R5, #-1

search_loop
CMP R4, R1 BGE not_found

LDR R6, [R0, R4, LSL #2]


CMP R6, R3 BEQ found

ADD R4, R4, #1 B search_loop

found
LDR R7, =result
STR R4, [R7]
B end

not_found
LDR R7, =result STR R5, [R7]

end
B end
AREA data, DATA, READWRITE
array DCD 22, 45, 67, 90, 12, 88 key
DCD 90
result DCD 0
END

OutPut

Q.8 Write a program to check whether the give string is palindrome or


not.

</> Code
AREA RESET, CODE, READONLY
ENTRY
EXPORT __main

__main
LDR R0, =string
LDR R1, =result
MOV R2, #0 find_len
LDRB R3, [R0, R2]
CMP R3, #0
BEQ check_palindrome
ADD R2, R2, #1 B find_len

check_palindrome
MOV R4, #0
SUB R5, R2, #1 MOV R6, #1

compare_loop
CMP R4, R5 BGE done_check

LDRB R7, [R0, R4]


LDRB R8, [R0, R5]
CMP R7, R8
BNE not_palindrome

ADD R4, R4, #1


SUB R5, R5, #1 B compare_loop

not_palindrome
MOV R6, #0

done_check
STR R6, [R1]

end
B end
AREA data, DATA,
READWRITE string DCB "madam",
0 result DCD 0

END
Output

Q.9 Write a program to count the number of ones and zeros in two
consecutive memory locations.

</> Code
AREA RESET, CODE, READONLY
ENTRY
EXPORT __main

__main
LDR R0, =data
LDR R1, [R0]
LDR R2, [R0, #4]

MOV R3, #0
MOV R4, #0

MOV R5, #32 count_first


TST R1, #1
ADDNE R3, R3, #1
ADDEQ R4, R4, #1
LSR R1, R1, #1
SUBS R5, R5, #1
BNE count_first

MOV R5, #32 count_second


TST R2, #1
ADDNE R3, R3, #1
ADDEQ R4, R4, #1
LSR R2, R2, #1
SUBS R5, R5, #1
BNE count_second

; Store results in memory


LDR R6, =count_ones
STR R3, [R6]
LDR R6, =count_zeros
STR R4, [R6]
B
.
AREA data, DATA, READWRITE
data DCD 0xF0F0F0F0, 0x0F0F0F0F
count_ones DCD 0
count_zeros DCD 0

END
OutPut

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy