0% found this document useful (0 votes)
8 views

BCS402_Codes_Quick Note_FINAL

The document outlines a series of experiments for ARM7TDMI/LPC2148 microcontroller programming using Keil software, focusing on assembly language programs (ALP) to manipulate various registers and perform arithmetic operations. It details the structure and purpose of general and special purpose registers, the current program status register (CPSR), and introduces data types and endianness in ARM architecture. Additionally, it provides sample assembly programs for tasks such as data transfer, arithmetic, and logical operations, along with expected observations from the experiments.
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)
8 views

BCS402_Codes_Quick Note_FINAL

The document outlines a series of experiments for ARM7TDMI/LPC2148 microcontroller programming using Keil software, focusing on assembly language programs (ALP) to manipulate various registers and perform arithmetic operations. It details the structure and purpose of general and special purpose registers, the current program status register (CPSR), and introduces data types and endianness in ARM architecture. Additionally, it provides sample assembly programs for tasks such as data transfer, arithmetic, and logical operations, along with expected observations from the experiments.
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/ 15

RV Institute of Technology & Management®

Department of Computer Science & Engineering

EXPERIMENTS: 1 to 11
Conduct the following experiments by writing program using ARM7TDMI/LPC2148 usingan
evaluation board/simulator and the required software tool.
Experiment-1 Using Keil software, observe the various Registers, Dump, CPSR, with a simple
MODULE–1 Assembly Language Programs (ALP).

 Using Keil software


MICROCONTROLLER Practical Component of ARM (Page # 5 of 32)
Introduction to ARM7 (Page # 8 of 32)
How to open & Using the Software: Keil µVision4 (Page # 9 of 32) to (Page # 14 of 32)

ARM - REGISTERS
 Observing the Various Registers in ARM using Keil µVision 4
 GPR’s: General Purpose Registers (R0 to R10)
 GPR’s /Multipurpose Registers (R11/FP: Frame Pointer &
R12/IP: Intra Procedural Call

 Observing the Various Registers in ARM using Keil µVision4


 SPR’s: Special Purpose Registers (R13 to R15)
R13/SP: Stack Pointer
R14/LR: Link Register
R15/PC: Program Counter / Instruction Pointer

# Alias Purpose
R0 - GPR: General Purpose Registers
R1 - GPR: General Purpose Registers
R2 - GPR: General Purpose Registers
R3 - GPR: General Purpose Registers
R4 - GPR: General Purpose Registers
R5 - GPR: General Purpose Registers
R6 - GPR: General Purpose Registers
R7 - Holds Syscall Number
R8 - GPR: General Purpose Registers
R9 - GPR: General Purpose Registers
R10 - GPR: General Purpose Registers
R11 FP Frame Pointer
R12 IP Intra Procedural Call
R13 SP Stack Pointer
R14 LR Link Register
R15 PC Program Counter / Instruction Pointer
CPSR - Current Program Status Register

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

R0-R12: can be used during common operations to store temporary values, pointers (locations to
memory), etc. R0, for example, can be referred as accumulator during the arithmetic operations or for
storing the result of a previously called function. R7 becomes useful while working with syscalls as it
stores the syscall number and R11 helps us to keep track of boundaries on the stack serving as the frame
pointer (will be covered later). Moreover, the function calling convention on ARM specifies that the
first four arguments of a function are stored in the registers r0-r3.

R13: SP (Stack Pointer). The Stack Pointer points to the top of the stack. The stack is an area of
memory used for function-specific storage, which is reclaimed when the function returns. The stack
pointer is therefore used for allocating space on the stack, by subtracting the value (in bytes) we want to
allocate from the stack pointer. In other words, if we want to allocate a 32 bit value, we subtract 4 from
the stack pointer.

R14: LR (Link Register). When a function call is made, the Link Register gets updated with a memory
address referencing the next instruction where the function was initiated from. Doing this allows the
program return to the “parent” function that initiated the “child” function call after the “child” function
is finished.

R15: PC (Program Counter). The Program Counter is automatically incremented by the size of the
instruction executed. This size is always 4 bytes in ARM state and 2 bytes in THUMB mode. When a
branch instruction is being executed, the PC holds the destination address. During execution, PC stores
the address of the current instruction plus 8 (two ARM instructions) in ARM state, and the current
instruction plus 4 (two Thumb instructions) in Thumb(v1) state. This is different from x86 where PC
always points to the next instruction to be executed.

 About CPSR / Current Program Status Register

N Z C V Q J GE E A I F T M
Greater
Overflow Flag
Negative Flag

Abort disable

Processor
IRQ disable

FIQ disable
Endianness
Carry Flag

Underflow
Zero Flag

than Thumb
Jazelle

Mode
Equal
(Privilige
for
Mode)
SIMD

N - Negative Flag Set when the result of the operation was Negative.
Z - Zero Flag Set when the result of the operation was Zero.
C - Carry Flag Set when the operation resulted in a Carry.
V - Overflow Flag Set when the operation caused oVerflow.
ARM can operate either in little endian, or big endian. This bit is set to 0
E - Endian-bit
for little endian, or 1 for big endian mode.
I IRQ – Disable
F FRQ – Disable
This bit is set if you are in Thumb state and is disabled when you are in
T - Thumb-bit
ARM state.
M - Mode-bits These bits specify the current privilege mode (USR, SVC, etc.).

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Before proceeding to the Execution of Sample Program: Lets know about below details

DATA TYPES
This is part of the ARM Assembly Language Programming Basics, covering data types
Similar to high level languages, ARM supports operations on different data types.

The data types we can load (or store) can be signed


and unsigned words, halfwords, or bytes. The
extensions for these data types are:
-h or -sh for halfwords,
-b or -sb for bytes,
and no extension for words. The difference
between signed and unsigned data types is

Unsigned data types can hold large positive values


Signed data types can hold both positive and
(including ‘Zero’) but cannot hold negative values
negative values and are therefore lower in range.
and are therefore wider in range.

ENDIANNESS
There are two basic ways of viewing bytes in memory: Little-Endian (LE) or Big-Endian (BE). The difference
is the byte-order in which each byte of an object is stored in memory. On little-endian machines like Intel x86,
the Least-significant-byte / LSB is stored at the lowest address (the address closest to zero). On big-endian
machines the Most-significant-byte / MSB is stored at the lowest address. The ARM architecture was little-
endian before version 3, since then it is bi-endian, which means that it features a setting which allows for
switchable endianness. On ARMv6 for example, instructions are fixed little-endian and data accesses can be
either little-endian or big-endian as controlled by bit 9, the E bit, of the Program Status Register (CPSR).

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Here are some examples of how these data types can be used with the instructions Load & Store:
LOAD INSTRUCTION DATA TYPES STORE INSTRUCTION DATA TYPES
ldr = Load Word str = Store Word
ldrh = Load unsigned Half Word strh = Store unsigned Half Word
ldrsh = Load signed Half Word strsh = Store signed Half Word
ldrb = Load unsigned Byte strb = Store unsigned Byte
ldrsb = Load signed Bytes strsb = Store signed Byte

Experiment-1 Using Keil software, observe the various Registers, Dump, CPSR, with a simple Assembly
MODULE–1 Language Programs (ALP).
Sample & simple Assembly Language Programs (ALP) to observe the movement of date in various Registers
GPR’s & CPSR

AREA Program, CODE, READONLY


ENTRY

MOV R0, #0009


MOV R1, #009
MOV R2, #09
MOV R3, #9
MOV R4, #0001
MOV R5, #0002
MOV R6, #0003
MOV R7, #0004
MOV R8, #0005
MOV R9, #0006
MOV R10, #0010
MOV R11, #15
MOV R12, #0255

here B here
END
CPSR / Current Program Status SPSR / Saved Program Status Register
Register CPSR consists of 8-Flags
Default filling of Flags

RESET=0
N,Z,C & V
N = Negative Flag
Z = Zero Flag
C = Carry Flag
V = Overflow Flag

SET=1
F&I
F = First Interrupt Flag
I = Interrupt Flag

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering
Experiment-1 Using Keil software, observe the various Registers, Dump, CPSR, with a simple Assembly
MODULE–1 Language Programs (ALP).
Sample & simple Assembly Language Programs (ALP) to perform Dump operation or just a Dumping process.
; SIMPLE ASSESMBLY LANGUAGE PROGRAM/ALP TO MULTIPLY GPR’s / General Purpose Registers
;(Z = X*Y) USING MEMORY Locations
AREA Program, CODE, READONLY
ENTRY
LDR R0, MEMORY
;load MEMORY LOCATION ADDRESS/MLA 0x40000000 to R0
LDRH R1, [R0]
;X=0004 load 16-Bits First number, MLA 0x40000000 & 01 to R1
LDRH R2, [R0,#2]
;Y=0003 load 16-Bits Second number, MLA 0x40000002 & 03 to R2
MUL R3, R2, R1
;Perform MULTIPLICATION Z=X*Y store the result in R3
STR R3, [R0, #4]
;move and store the 32-Bits result Z to MLA 0x40000004 on wards

here B here
;Unconditional Branching LABEL name is here
;all done conclude here

MEMORY DCD 0x40000000


;MLA used in our MULTIPLICATION ALP program

END
CPSR / Current Program Status Register SPSR / Saved Program Status Register
CPSR consists of 8-Flags
Default filling of Flags

RESET=0
N,Z,C & V
N = Negative Flag
Z = Zero Flag
C = Carry Flag
V = Overflow Flag

SET=1
F&I
F = First Interrupt Flag
I = Interrupt Flag

Dump: The process of storing/pushing inside the Memory & retrieving/popping up the value from the
Memory is called Dump or just a Dumping process.
32-Bits output Z=0000000C
Dumping the 16-Bits input X=0004 Dumping the 16-Bits input Y=0003 (Z = X*Y) 12 = 4 * 3
Inside the MEMORY LOCATION Inside the MEMORY LOCATION C = 12 in Decimal
Inside the MEMORY LOCATION

MLA 0x40000000 MLA 0x40000002


& & MLA 0x40000004
MLA 0x40000001 MLA 0x40000003 TO
MLA 0x40000007

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-2 Develop and simulate ARM ALP for Data Transfer, Arithmetic and Logical operations
MODULE–2 (Demonstrate with the help of a suitable program).
AREA MULTIPLY, CODE, READONLY OBSERVATOION OF
ENTRY ; Mark first instruction to execute OUTPUT INSIDE
GPR’s / General Purpose Registers
START FOR ARTHEMATIC OPERATONS
MOV R1, #6400
ADDITION Y=A+B inside R3
; 1900 in HEX STORE FIRST NUMBER/A IN R1
MOV R2, #3200
; 0C80 in HEX STORE SECOND NUMBER/B IN R2

;PERFORMING ARTHEMATIC OPERATIONS


ADD R3, R2, R1
;R3/Y = A+B(9600=3200+6400)2580 in HEX

SUB R4, R1, R2


;R4/Y = A-B(3200=3200+6400)0C80 in HEX SUBRATION Y=A-B inside R4

MUL R5, R2, R1


;R5/Y = A*B(2,04,80,000=3200+6400)01388000 in HEX

;PERFORMING LOGICAL OPERATIONS


AND R6, R2, R1
;R6/Y = A AND B (00000800 in HEX)

ORR R7, R2, R1


MULTIPLICATION Y=A-B inside R5
;R7/Y = A OR B (00000800 in HEX)

EOR R8, R2, R1


;R8/Y = A EX-OR B

BIC R9, R2, R1


;R9/Y = A OR B

HERE B HERE;
END ; Mark end of file
OBSERVATOION OF LOGICAL OPERATION OUTPUT’S
AND OPERATION OR OPERATION EX-OR OPERATION

Y=A AND B inside R6 Y=A OR B inside R7 Y=A EX-OR B inside R8

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-3
Develop an ALP to multiply two 16-bit binary numbers.
MODULE–2

AREA MULTIPLY, CODE, READONLY

ENTRY
; Mark first instruction to execute

START

MOV r1, #6400


; STORE FIRST NUMBER IN R1

MOV r2, #3200


; STORE SECOND NUMBER IN R2

MUL r3, r2, r1


; Perform MULTIPLICATION store result in R3

here b here
;Unconditional Branching LABEL name is here
;all done conclude here

END
; Mark end of file

OBSERVATOION OF OUTPUT INSIDE


GPR’s / General Purpose Registers

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-4
Develop an ALP to find the sum of first 10 integer numbers.
MODULE–2
OBSERVATOION OF
AREA SUM, CODE, READONLY OUTPUT INSIDE
GPR’s / General Purpose Registers
ENTRY

MOV R1, #10


;load 10 to register
MOV R2, #0
;empty the register to store result

loop
ADD R2, R2, R1
; add the content of R1 with result at R2
SUBS R1, #0x01
; Decrement R1 by 1
BNE loop
; repeat till r1 becomes 0

back B back
; Unconditional Branching LABEL name is back

END

OBSERVATOION OF FINAL OUTPUT inside R2 GPR

SUM of First 10-Interger Numbers

55 in
10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 =
DECIMAL
37 in
HEXA-DECIMAL

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-5 Experiment 5: (5a: LARGEST & 5b: SMALLEST)


MODULE–2 Experiment 5a: To find LARGEST of a number in an ARRAY.
AREA LARGEST, CODE, READONLY
ENTRY OBSERVATOION OF
; Mark first instruction to execute FINAL OUTPUT
START
MOV R5, #6
inside R2 GPR
; INTIALISE COUNTER TO 6 (i.e.N=7)

LDR R1, =VALUE1


; LOADS THE ADDRESS

LDR R2, [R1], #4


; WORD ALIGN T0 ARRAY ELEMENT
LOOP
LDR R4, [R1], #4
; WORD ALIGN T0 ARRAY ELEMENT

CMP R2, R4
; COMPARE NUMBERS
R5 GPR is used as a counter
BHI LOOP1 Execute the code (Single Step)
; IF THE FIRST NUMBER IS > THEN GO TO LOOP1
Until R5 becomes zero
MOV R2, R4
; IF THE FIRST NUMBER IS < THEN MOV CONTENT R4 TO R2 Element AAAAAAAA is
LARGEST in the ARRAY
LOOP1 Should load to R2 Finally
SUBS R5, R5, #1
; DECREMENTCOUNTER

CMP R5, #0
; COMPARE COUNTER TO 0

BNE LOOP
; LOOP BACK TILL ARRAY ENDS
LDR R4, =RESULT
; LOADS THE ADDRESS OF RESULT
STR R2, [R4]
; STORES THE RESULT IN R2
NOP
back B back
; ARRAY OF 32-BIT NUMBERS (N=7)
VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999
AREA DATA2, DATA, READWRITE
;TO STORE RESULT IN GIVEN ADDRESS
RESULT DCD 0X0
END ;Mark end of file

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-5 Experiment 5: (5a: LARGEST & 5b: SMALLEST)


MODULE–2 Experiment 5b: To find SMALLEST of a number in an ARRAY.
AREA SMALLEST, CODE, READONLY
ENTRY OBSERVATOION OF
; Mark first instruction to execute FINAL OUTPUT
START
MOV R5, #6
inside R2 GPR
; INTIALISE COUNTER TO 6 (i.e.N=7)

LDR R1, =VALUE1


; LOADS THE ADDRESS

LDR R2, [R1], #4


; WORD ALIGN T0 ARRAY ELEMENT
LOOP
LDR R4, [R1], #4
; WORD ALIGN T0 ARRAY ELEMENT

CMP R2, R4
; COMPARE NUMBERS
R5 GPR is used as a counter
BLS LOOP1 Execute the code (Single Step)
; IF THE FIRST NUMBER IS > THEN GO TO LOOP1
Until R5 becomes zero
MOV R2, R4
; IF THE FIRST NUMBER IS < THEN MOV CONTENT R4 TO R2 Element 11111111 is
SMALLEST in the ARRAY
LOOP1 Should load to R2 Finally
SUBS R5, R5, #1
; DECREMENTCOUNTER

CMP R5, #0
; COMPARE COUNTER TO 0

BNE LOOP
; LOOP BACK TILL ARRAY ENDS
LDR R4, =RESULT
; LOADS THE ADDRESS OF RESULT
STR R2, [R4]
; STORES THE RESULT IN R2
NOP
back B back
; ARRAY OF 32-BIT NUMBERS (N=7)
VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999
AREA DATA2, DATA, READWRITE
;TO STORE RESULT IN GIVEN ADDRESS
RESULT DCD 0X0
END ;Mark end of file

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-6 Develop an ALP to count the number of ones and zeros in two consecutive
MODULE–2 Memory locations.
AREA ONEZERO, CODE, READONLY Input the 32-bits / 8-digit
ENTRY DECIMAL VALUE inside the
LDR R0, MEMORY MEMORY LOCATION
; Load Address Memory ADDRESS
LDR R1,[R0] 40000000 TO 40000007
; Load 32bit Number INPUT VALUE:
MOV R4, #32 01010000
; Load rotation Count
OBSERVATOION OF
ROTATE
FINAL OUTPUT
RORS R1, #1 inside R2 GPR hold the
; Rotate right by 1 bit, update number of 1’s count will be in
CPSR hex value, total number of
BCS ONES ONE’S
; is carry =1
ADD R3,R3,#1 in the INPUT VULUE is 2
; increment 0 count
B NEXT inside R3 GPR hold the
; Branch to next Rotation number of 0’s count will be in
hex value, total number of
ONES
ZERO’S
ADD R2,R2,#1 in the INPUT VULUE is 30
; increment 1 count (1E in HEX value)
NEXT
ADD R4,R4,#-1
; Decrement Rotation Count
CMP R4, #0
; if Rotation EQ to 0
BNE ROTATE
; if No, goto Rotate
ADD R0,R0,#04
; Add Address of no. of 1's
STRB R2,[R0]
; Store No. of 1's
ADD R0, R0, #1
; Load address of no. of 0's

STRB R3, [R0]


; Store No. of 0's
Here B Here R4 GPR is used as a counter
MEMORY DCD 0X40000000 Execute the code (Single Step)
; Memory address Until R4 becomes zero
END

INPUT VULUE = 00000101


0 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1
TOTAL NUMBER OF ONE’S = 2 TOTAL NUMBER OF ZER’S = 30

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-7 Simulate a program in C for ARM microcontroller using KEIL to sort the
MODULE–3 numbers in ascending / descending order using bubble sort.
Experiment 7a: To sort ASCENDING ORDER using bubble sort TECHNIQUE.
#include <LPC214x.h>
#include <stdio.h> INPUT UNSORTED ARRAY
using CALL STACK
// Function to swap two numbers
void swap(int *xp, int *yp) {
int temp = *xp;
*xp = *yp;
*yp = temp;
}

// Function to perform bubble sort in ascending order


void bubbleSortAscending(int arr[], int n) {
int i, j;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
swap(&arr[j], &arr[j+1]);
}
}
}
}

// Function to print an array


void printArray(int arr[], int size) { OBSERVATOION OF
int i; FINAL OUTPUT
for (i = 0; i < size; i++) { OUTPUT ASCENDING SORTED ARRAY
printf("%d ", arr[i]); using CALL STACK
}
printf("\n");
}

int main() {
int arr[] = {2,6,8,7,9,4,1,3,5};
int n = sizeof(arr)/sizeof(arr[0]);

bubbleSortAscending(arr, n);
printf("Sorted array in ascending order: \n");

printArray(arr, n);
printf("Original array: \n");
printArray(arr, n);

return 0;
}

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-7 Simulate a program in C for ARM microcontroller using KEIL to sort the
MODULE–3 numbers in ascending / descending order using bubble sort.
Experiment 7b: To sort DESCENDING ORDER using bubble sort TECHNIQUE.
#include <LPC214x.h>
#include <stdio.h> INPUT UNSORTED ARRAY
using CALL STACK
// Function to swap two numbers
void swap(int *xp, int *yp) {
int temp = *xp;
*xp = *yp;
*yp = temp;
}

// Function to perform bubble sort in descending order


void bubbleSortDescending(int arr[], int n) {
int i, j;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] < arr[j+1]) {
swap(&arr[j], &arr[j+1]);
}
}
}
}

// Function to print an array


void printArray(int arr[], int size) { OBSERVATOION OF
int i; FINAL OUTPUT
for (i = 0; i < size; i++) { OUTPUT ASCENDING SORTED ARRAY
printf("%d ", arr[i]); using CALL STACK
}
printf("\n");
}

int main() {
int arr[] = {2,6,8,7,9,4,1,3,5};
int n = sizeof(arr)/sizeof(arr[0]);

bubbleSortDescending(arr, n);
printf("Sorted array in descending order: \n");
printArray(arr, n);

printArray(arr, n);
printf("Original array: \n");
printArray(arr, n);

return 0;
}

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-8 Simulate a program in C for ARM microcontroller to find factorial of a


MODULE–3 number.

STORAGE OF ELEMENTS of Number 5


#include <LPC214x.h> In CALL STACK
#include <stdio.h>

// Function to find the factorial of a number


unsigned long long int factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}

int main() {
int num;
unsigned long long int result;

// Simulate user input (you can replace this with


actual input method)
num = 5; OBSERVATOION OF
FINAL OUTPUT
OUTPUT
// Calculate factorial OF 5 X 4 X 3 X 2 X 1 is 120 in Decimal Value
result = factorial(num);
(78 in HEX VALUE)
inside CALL STACK
// Print result
printf("Factorial of %d is %llu\n", num, result);

return 0;
}

INPUT OF FACTORIAL
Number Is 5

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES
RV Institute of Technology & Management®
Department of Computer Science & Engineering

Experiment-9 Simulate a program in C for ARM microcontroller to demonstrate case


MODULE–3 conversion of characters from upper to lowercase and lower to uppercase.
#include <LPC214x.h>
#include <stdio.h> INPUT string inside the
CALL STACK

// Function to convert a character's case


char convertCase(char c) {
// If the character is lowercase, convert to uppercase
if (c >= 'a' && c <= 'z') {
return c - 'a' + 'A';
}
// If the character is uppercase, convert to lowercase
else if (c >= 'A' && c <= 'Z') {
return c - 'A' + 'a';
}
// If it's neither, return the character as is
return c;
}

int main() {
char str[] = "hello rvitm"; // Example string
int i = 0;

//printf("Original string: %s\n", str); OBSERVATOION OF


FINAL OUTPUT
// Convert the case of each character in the string CASE CONVERSION
while (str[i] != '\0') { inside CALL STACK
str[i] = convertCase(str[i]);
i++;
}

//printf("Converted string: %s\n", str);

return 0;
}

Prepared By: Santhosh Kumar K.P, Programmer, Dept of CSE, RVITM. IPCC: BCS402/MC Lab: Quick Ref NOTES

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