You are on page 1of 8

6.

To write and simulate ARM assembly language programs for data


transfer, arithmetic and logical operations (Demonstrate with the help
of a suitable program).
Creating an Assembly project in Keil
1. Open your Keil uVision4 IDE software, Go to Project tab>>Click on
New uVision Project.
2. Select a drive where you would like to create your project .Create a new folder and Name it
FirstProject. Type the name FirstProject for the project and click Save. Open that project folder
and give a name of your project executable file and save it.
3. In the Data base tree, choose the vendor and then the chip you want to use and then click
OK. For example, if you want to use the LPC2148, click on the ARM/NXP and then on the
LPC2148 and then press OK.
4. After selecting chip click on OK then it will display some window asking to add STARTUP
file. Click the No button when add the startup file to the project pop up window is displayed
A target is created .
5. To write your project code select a new file from FILE menu bar or Make a new file by
clicking on the New Icon. Press Ctrl+S to save the new file. (You can also save the file by
choosing Save from the File menu.).Name the file as program1.asm and save it in the
FirstProject directory.
6. Type the program in the file
7. Add the program1.asm file to the project. To do so: a. Right click on Source Group 1 and
choose Add Files to Group. Then go to the FirstProject directory and choose Program1.asm,
press Add and then Close. The file will be added to target and it shows in the project
window.
Building
1. Now give a right click on target in the project window and selectOptions for Target.
2. It will show a window, in that go to output option and choose Create Hex file option by
selecting that box.In the same window go to Linker option and choose Use Memory Layout
from Target Dialog by selecting the box, and click OK.
3. To compile your project go to Project select Build Target option or press F7.
4. In the build OUT PUT window you can see the errors and warnings in your code. And here
Your project Hex file will be created

Debugging and Tracing


1. To start debugging click on Start/Stop Debug Session icon or choose Start/Stop Debug
Session from the Debug menu. (or simply press Ctrl+F5)
2. If it starts tracing successfully, a cursor appears in front of the next instruction to be
executed.
RunF5Runs the program until it hits a breakpoint or the end of the program.
Step IntoF11Steps through the code and follows into functions.
Step OverF10Steps through the code and jumps over functions.
Step OutCtrl+F11Step out of a function
3. The debugger will monitor the CPUs registers and update their values in the register bank
on the left side of the window
4. The Memory window displays the memory area content. Several memory windows can be
used at a time. Open the windows from the toolbar or using the menu View - Memory
Windows.
5. To exit from the debugging mode press Start/Stop Debug Session.
DATA TRANSFER INSTRUCTIONS

1. 32 bit Block Transfer from Location A to Location B

AREA Program, CODE, READONLY


ENTRY
start
MOV R0,#0x40000000
MOV R1,#0X4000003F
MOV R4,#0X05
loop LDR R2,[R0] ;load the value to be moved
STR R2,[R1] ;store it back in a different location
ADD R0, R0,#+4
ADD R1, R1,#+4
SUBS R4, R4,#0X01
BNE loop
SAME B SAME
END

Before execution
40000000: 11 22 33 44
After execution
4000003F:11 22 33 44

2. 16 bit Block Transfer from Location A to Location B

TTL 16bitdatatrans
AREA Program, CODE, READONLY
ENTRY
START
LDRB R1, VALUE
STR R1, RESULT
SWI &11
VALUE DCW &C123
ALIGN
RESULT DCW 0
END
ARITHMETIC INSTRUCTIONS

3. Addition of two 32 bit numbers

AREA Program, CODE, READONLY


ENTRY
start
MOV R0,#0x40000000
LDR R1,[R0]
ADD R0,R0,#04
LDR R2,[R0]
ADDS R1,R1,R2
ADD R0,R0,#04
STR R1,[R0]
SAME B SAME
END

Before execution
40000000: 11 22 33 44
40000004:55 66 77 88
After execution
40000008: CC AA 88 66
4. Addition of two 32 bit numbers and Store the result with Carry
in Memory
AREA Program, CODE, READONLY
ENTRY
start
MOV R0,#0x40000000
LDR R1,[R0]
ADD R0,R0,#04
LDR R2,[R0]
ADDS R1,R1,R2
ADD R0,R0,#04
STR R1,[R0]
EOR R1,R1,R1
ADC R1,R1,#0X00
ADD R0,R0,#04
STR R1,[R0]
SAME B SAME
END
Before execution
40000000: 11 22 33 44
40000004:55 66 77 88
After execution
40000008: CC AA 88 66
5. Addition of two 16 bit numbers

TTL 16bitadd
AREA Program, CODE, READONLY
ENTRY
START
VALUE1 DCW &C123
ALIGN
VALUE1 DCW &02AA
ALIGN
RESULT DCW 0
LDR R1, VALUE1
LDR R2, VALUE2
ADD R1, R1, R2
STR R1, RESULT
HERE
B HERE
END

Input R1: C123


R2:02AA
Output Result: C3CD
6. Multiplication of two 32 bit numbers stored in memory & Store
the result in memory

AREA Program, CODE, READONLY


ENTRY
start
MOV R2,#0x40000000
LDR R0,[R2]
ADD R2,R2,#04
LDR R1,[R2]
UMULL R6,R8,R1,R0
ADD R2,R2,#04
STR R8,[R2]
ADD R2,R2,#04
STR R6,[R2]
SAME B SAME
END

Input R1: 002468AC


R0:03281088
Output
PRODUCT
R6:R8 000072ECB8C25B60
Logical Instructions
7. ANDing of two 32 bit numbers

AREA Program, CODE, READONLY


ENTRY
start
MOV R0,#0x40000000
LDR R1,[R0]
ADD R0,R0,#04
LDR R2,[R0]
AND R1,R1,R2
ADD R0,R0,#04
STR R1,[R0]
SAME B SAME
END

Input R1:
Output R2:

8. Ones complement of a given number

TTL ONESCOMP

AREA Program, CODE, READONLY


ENTRY
START
VALUE DCD &C123
; DCD directive allocates one or more words of memory, aligned on 4-byte
boundaries
RESULT DCW 0
LDR R1, VALUE ; load the number to be complemented
MVN R1, R1 ; complement the contents of R1
STR R1, RESULT
SAME B SAME
END

Input Value: 0000C123


Output Result: FFFF3EDC

You might also like