ARM programs (Basic)
So I was asked to write a few programs as a homework assignment. Was really simple but was a good exercise with the assembly codes.
ARM Assembly Home Work 2
Date 02/10/11
Abishek Ramdas
1. x = (a+b);
ADR r4, a ;get address of variable 'a'
LDR r0, [r4] ;load the valuf of 'a' into r0. r0 <- a
ADR r4, b ;get address of b into r4
LDR r1, [r4] ;r1 <- b
ADD r3, r1, r0 ;r3 <- a+b
LDR r4, x ;get addres of x into r4
STR rs, [r4] ;x <- (a+b)
2. y = (c-d) + (e-f)
ADR r4, c
LDR r0,[r4] ;r0 <- c
ADR r4, d
LDR r1, [r4] ;r1 <- d
SUB r3, r0, r1 ;r3 <- (r0-r1) or r3 <- (c-d)
ADR r4, e
LDR r0,[r4] ;r0 <- e
ADR r4, f
LDR r1,[r4] ;r0 <- f
SUB r5, r0, r1 ;r5 <- (r0-r1) or r5 <- (e-f)
ADD r6, r3, r5 ;r6 <- r3+r5 or r6 <- (c-d)+ (e-f)
ADR r4, y
STR r6, [r4] ;y <- r6 or y <- (c-d)+ (e-f)
3. z = a*(b+c) - d*e
ADR r4, a
LDR r0, [r4] ;r0 <- a
ADR r4, b
LDR r1, [r4] ;r1 <- b
ADR r4, c
LDR r2, [r4] ;r2 <- c
ADD r3, r1, r2 ;r3 <- (r1+r2) or r3 <- (b+c)
MUL r1, r0, r3 ;r1,r2 <- (r0*r3) or r1,r2 <- a*(b+c) (64 bit result)
ADR r4, d
LDR r5, [r4] ;r5 <- d
ADR r4, e
LDR r6, [r4] ;r6 <- e
MUL r3, r5, r6 ;r3,r4 <- (r5*r6) or r3,r5 <- d*e (64 bit result)
SBC r6, r2, r4 ;r6 <- (r2-r4) the subtract with carry of Least significant 32 bits of a*(b+c) and d*e
SUB r5, r1, r3 ;r5 <- (r1-r3) the subtract of Most significant 32 bits of a*(b+c) and d*e
;r5,r6 contains the resulting 64 bit value of a*(b+c) - d*e
ADR r4, z
STR r5, [r4] ;Assuming little endian configuration, z contains the most significant 32 bits
ADR r4, z+1 ;next 32 bit word
STR r6, [r4] ;Assuming little endian configuration, z+1 contains the least significant 32 bits
A really good book for ARM ASM programming is "ARM system developer's guide: designing and optimizing system software [Book] by Andrew N. Sloss, Dominic Symes, Chris Wright in Books".
I found it very interesting in the manner it explains each instruction and how its execution affects the state of the processor. Not the book prescribed in the syllabus though. The book prescribed in the syllabus is "Computers as components: principles of embedded computing system By Wayne Hendrix Wolf ".
From this book I learnt the importance of Foralism in system description and a Unified Modelling Language for the behavioural and structural descriptions of a system. Will definitely use UML to describe my system in my project.
ARM Assembly Home Work 2
Date 02/10/11
Abishek Ramdas
1. x = (a+b);
ADR r4, a ;get address of variable 'a'
LDR r0, [r4] ;load the valuf of 'a' into r0. r0 <- a
ADR r4, b ;get address of b into r4
LDR r1, [r4] ;r1 <- b
ADD r3, r1, r0 ;r3 <- a+b
LDR r4, x ;get addres of x into r4
STR rs, [r4] ;x <- (a+b)
2. y = (c-d) + (e-f)
ADR r4, c
LDR r0,[r4] ;r0 <- c
ADR r4, d
LDR r1, [r4] ;r1 <- d
SUB r3, r0, r1 ;r3 <- (r0-r1) or r3 <- (c-d)
ADR r4, e
LDR r0,[r4] ;r0 <- e
ADR r4, f
LDR r1,[r4] ;r0 <- f
SUB r5, r0, r1 ;r5 <- (r0-r1) or r5 <- (e-f)
ADD r6, r3, r5 ;r6 <- r3+r5 or r6 <- (c-d)+ (e-f)
ADR r4, y
STR r6, [r4] ;y <- r6 or y <- (c-d)+ (e-f)
3. z = a*(b+c) - d*e
ADR r4, a
LDR r0, [r4] ;r0 <- a
ADR r4, b
LDR r1, [r4] ;r1 <- b
ADR r4, c
LDR r2, [r4] ;r2 <- c
ADD r3, r1, r2 ;r3 <- (r1+r2) or r3 <- (b+c)
MUL r1, r0, r3 ;r1,r2 <- (r0*r3) or r1,r2 <- a*(b+c) (64 bit result)
ADR r4, d
LDR r5, [r4] ;r5 <- d
ADR r4, e
LDR r6, [r4] ;r6 <- e
MUL r3, r5, r6 ;r3,r4 <- (r5*r6) or r3,r5 <- d*e (64 bit result)
SBC r6, r2, r4 ;r6 <- (r2-r4) the subtract with carry of Least significant 32 bits of a*(b+c) and d*e
SUB r5, r1, r3 ;r5 <- (r1-r3) the subtract of Most significant 32 bits of a*(b+c) and d*e
;r5,r6 contains the resulting 64 bit value of a*(b+c) - d*e
ADR r4, z
STR r5, [r4] ;Assuming little endian configuration, z contains the most significant 32 bits
ADR r4, z+1 ;next 32 bit word
STR r6, [r4] ;Assuming little endian configuration, z+1 contains the least significant 32 bits
A really good book for ARM ASM programming is "ARM system developer's guide: designing and optimizing system software [Book] by Andrew N. Sloss, Dominic Symes, Chris Wright in Books".
I found it very interesting in the manner it explains each instruction and how its execution affects the state of the processor. Not the book prescribed in the syllabus though. The book prescribed in the syllabus is "Computers as components: principles of embedded computing system By Wayne Hendrix Wolf ".
From this book I learnt the importance of Foralism in system description and a Unified Modelling Language for the behavioural and structural descriptions of a system. Will definitely use UML to describe my system in my project.
Comments
Post a Comment