Dayananda Sagar University
School of Engineering
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING
Computer Organization and Architecture
Course Code: 23CS2405
Assignment 1
Name: SIDDI SHASHANK REDDY
USN: ENG23CS0462
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
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