In: Computer Science
how multiplication of two numbers (50 & 25) stored in RAM is carried out on the Cortex-M4 processor using the MUL instruction.
ARM has 37 registers all of which are 32-bits long.
1 dedicated program counter
1 dedicated current program status register
5 dedicated saved program status registers
30 general purpose registers
The current processor mode governs which of several banks is accessible. Each mode can access
a particular set of r0-r12 registers a particular r13 (the stack pointer, sp) and r14 (the link register, lr)
the program counter, r15 (pc)
the current program status register, cpsr Privileged modes (except System) can also access
a particular spsr (saved program status register)
Program to multiply two 16 bit numbers
AREA MULTIPLY , CODE, READONLY
ENTRY
START
MOV r1, #50 ;32(hex)
MOV r2, #25 ;19(hex)
MUL r3,r1,r2 ;1250 0x000004E2
stop B stop
END
Area is Assembler directive ,and we gave a name Multiply which is user specified (you can give any name),similarly directive code is Readonly and Entry is the starting point of the program.Start is the label.The first instruction is MOV in which we directly giving the value 50 so it is preceded by # symbol.The number in the assembler is stored in hexadecimal notation so we specify 32 equivalent of 50 in decimal.Mul is a instruction which multiplies 50 and 25 and store the result in r3. B is a instruction which means branch to a line labelled with the word stop that means it has to branch back to the same line that is it goes in an infinite loop ,this way is a convenient way to end the program.
In order to execute the program on klein microvision 4 you need to make a project with a name mul and then you have to select lpc 2148 in the cpu of target 1 and then click ok. When the dialogue page pop up select no as we are doing Assembly programming. After this click on file select new .it opens text file here you need to type your program.Intend the first line by pressing a tab as area and end should not come in first column as it is stored for labels.Save the file give the name.s extension.Then go to project-- manage --component environment components--
select all source files and then click on add and then ok..To compile theprogram click on build option. And then debug the program and then run it.