MClabprgm
MClabprgm
Using Keil software, observe the various Registers, Dump, CPSR, with a simple Assembly
Language Programs (ALP).
END
**********************************************************************************
**********************************************************************************
This is how the code should look like:-
3. Develop an ALP to multiply two 16-bit binary numbers.
START
MOV r1,#0X1900
MOV r2,#0X0C80
MUL r3,r1,r2
STOP B STOP
END
**********************************************************************************
**********************************************************************************
This is how the code should look like:-
5. Develop an ALP to find the largest/smallest number in an array of 32 numbers.
Largest:-
LOOP
ADD R0, R0, #4 ; Move to next element
LDR R3, [R0] ; Load next element into R3
CMP R2, R3 ; Compare current max with next element
BHS SKIP_UPDATE ; If R2 >= R3, skip update
MOV R2, R3 ; Else update R2 with R3 (new max)
SKIP_UPDATE
SUBS R5, R5, #1 ; Decrement counter
BNE LOOP ; If not zero, repeat loop
STOP
B STOP ; Halt
ARRAY_DATA
DCD 0x25, 0x68, 0x25, 0xFF, 0x99, 0x12 ; Word-aligned data
END
**********************************************************************************
LOOP
ADD R0, R0, #4 ; Move to the next element
LDR R3, [R0] ; Load next array element into R3
CMP R2, R3 ; Compare current min with the new element
BLS SKIP_UPDATE ; If R2 <= R3, skip update
MOV R2, R3 ; Update R2 to new minimum
SKIP_UPDATE
SUBS R5, R5, #1 ; Decrement loop counter
BNE LOOP ; Repeat loop until all elements are checked
ARRAY_DATA
DCD 0x25, 0x68, 0x25, 0xFF, 0x99, 0x12, 0xAB ; Array of 7 elements
END
**********************************************************************************
NEXTBIT
MOVS R0, R0, ROR #1 ; Rotate right and update flags
BCS ONES ; If LSB was 1 (carry set), go to ONES
ZEROS ADD R3, R3, #1 ; R3 stores count of 0s
B REPEAT
END
**********************************************************************************
This is how the code should look like :-
7. Simulate a program in C for ARM microcontroller using KEIL to sort the numbers in
ascending/descending order using bubble sort.
Ascending :-
#include <lpc214x.h>
int main(void)
{
volatile int i, j, temp;
int arr[ ] = {4,1,3,5,2}; // the array to be sort
// bubble sort
for (i = 1; i < 5; i++)
{
for (j = 0; j < 5 - i; j++)
{
if (arr[j] > arr[j + 1]) // Compares first and second element of the array
{
temp = arr[j]; // If first element is greater, swap the elements of the array
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
while(1);
}
**********************************************************************************
#include <lpc214x.h>
int main(void)
{
volatile int i, j, temp;
int arr[] = {4, 1, 3, 5, 2}; // The array to be sorted (descending)
**********************************************************************************
#include <lpc214x.h>
int main()
{
volatile int n, i, fact = 1;
n = 5; // initialize the number
OR
**********************************************************************************
#include <lpc21xx.h>
int main(){
while(1);
}
**********************************************************************************
#include <lpc21xx.h>
void caseConvert() {
unsigned int i;
for (i = 0; src[i] != '\0'; i++) {
if (src[i] >= 'a' && src[i] <= 'z') {
dest[i] = src[i] - 32; // Lowercase to uppercase
} else if (src[i] >= 'A' && src[i] <= 'Z') {
dest[i] = src[i] + 32; // Uppercase to lowercase
} else {
dest[i] = src[i]; // Copy non-alphabet characters as-is
}
}
dest[i] = '\0'; // Null-terminate the output string
}
int main() {
caseConvert();
while (1); // Infinite loop to keep the program running
}
**********************************************************************************