Lilanka Udawatta
Published © GPL3+

Introduction to Assembly Language with Freescale

Disassembling a basic C programming code to obtain the machine translated assembly language.

IntermediateFull instructions provided1 hour2,508
Introduction to Assembly Language with Freescale

Things used in this project

Hardware components

NXP K20_100: Kinetis K20
×1
NXP FRDM-K20D50M for Kinetis K20 MCUs ARM mbed development platform brings web-based SDK
×1

Software apps and online services

NXP CodeWarrior Embedded

Story

Read more

Code

Assembly Language swap Function:

Assembly x86
The code for assembly swap and the disassembled C to assembly code shows how simple the code is in assembly language.

r0, r1, r2 and r3 are al registers used to hold temporary data. Writing a simple assembly code omits the need for the use of the stack. Hence the processing speed can be increased, and the use of space is sustainable.
**************************************************/

.text
.align 2
.global swap
.type swap, function

/**************************************************

* Function swap
* Swaps two integers
* Return Parameters
* r0 - Num1 (a)
* r1 - Num2 (b)

***************************************************/

swap:

	ldr r2, [r0, #0] /*load r2 with content of r0*/
	ldr r3, [r1, #0] /*load r3 with content of r1*/
	str r3, [r0, #0] /* store content of r3 into r0*/
	str r2, [r1, #0] /*store content of r2 into r1*/
	bx lr /* branch to main with the return address saved in lr*/

Credits

Lilanka Udawatta

Lilanka Udawatta

6 projects • 41 followers
I am Electrical and Electronic engineering student, seeking for opportunities to create something that actually matter to the society.

Comments