How To Move A Decimal Value Into A Register In Arm
Associates - Numbers
Numerical data is generally represented in binary system. Arithmetic instructions operate on binary information. When numbers are displayed on screen or entered from keyboard, they are in ASCII form.
Then far, we have converted this input data in ASCII form to binary for arithmetic calculations and converted the upshot dorsum to binary. The post-obit code shows this −
department .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov eax,'3' sub eax, '0' mov ebx, 'four' sub ebx, '0' add together eax, ebx add eax, '0' mov [sum], eax mov ecx,msg mov edx, len mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov ecx,sum mov edx, 1 mov ebx,1 ;file descriptor (stdout) mov eax,iv ;system telephone call number (sys_write) int 0x80 ;call kernel mov eax,ane ;system call number (sys_exit) int 0x80 ;phone call kernel section .information msg db "The sum is:", 0xA,0xD len equ $ - msg segment .bss sum resb i
When the above code is compiled and executed, it produces the following result −
The sum is: 7
Such conversions, however, have an overhead, and associates linguistic communication programming allows processing numbers in a more than efficient way, in the binary form. Decimal numbers can exist represented in two forms −
- ASCII form
- BCD or Binary Coded Decimal form
ASCII Representation
In ASCII representation, decimal numbers are stored as string of ASCII characters. For example, the decimal value 1234 is stored every bit −
31 32 33 34H
Where, 31H is ASCII value for 1, 32H is ASCII value for 2, so on. In that location are four instructions for processing numbers in ASCII representation −
-
AAA − ASCII Adjust After Addition
-
AAS − ASCII Adjust Afterwards Subtraction
-
AAM − ASCII Suit Subsequently Multiplication
-
AAD − ASCII Conform Earlier Division
These instructions exercise not have any operands and presume the required operand to be in the AL register.
The post-obit example uses the AAS instruction to demonstrate the concept −
section .text global _start ;must be declared for using gcc _start: ;tell linker entry indicate sub ah, ah mov al, '9' sub al, '3' aas or al, 30h mov [res], ax mov edx,len ;message length mov ecx,msg ;message to write mov ebx,one ;file descriptor (stdout) mov eax,iv ;arrangement call number (sys_write) int 0x80 ;telephone call kernel mov edx,1 ;message length mov ecx,res ;message to write mov ebx,one ;file descriptor (stdout) mov eax,4 ;organization call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'The Upshot is:',0xa len equ $ - msg section .bss res resb one
When the above lawmaking is compiled and executed, information technology produces the following result −
The Result is: half dozen
BCD Representation
There are two types of BCD representation −
- Unpacked BCD representation
- Packed BCD representation
In unpacked BCD representation, each byte stores the binary equivalent of a decimal digit. For instance, the number 1234 is stored as −
01 02 03 04H
In that location are two instructions for processing these numbers −
-
AAM − ASCII Adjust Afterwards Multiplication
-
AAD − ASCII Adjust Before Division
The four ASCII arrange instructions, AAA, AAS, AAM, and AAD, can as well be used with unpacked BCD representation. In packed BCD representation, each digit is stored using four bits. Two decimal digits are packed into a byte. For example, the number 1234 is stored as −
12 34H
There are two instructions for processing these numbers −
-
DAA − Decimal Adjust Afterwards Addition
-
DAS − decimal Adjust After Subtraction
There is no support for multiplication and division in packed BCD representation.
Example
The following program adds up two 5-digit decimal numbers and displays the sum. It uses the above concepts −
section .text global _start ;must exist alleged for using gcc _start: ;tell linker entry indicate mov esi, 4 ;pointing to the rightmost digit mov ecx, five ;num of digits clc add_loop: mov al, [num1 + esi] adc al, [num2 + esi] aaa pushf or al, 30h popf mov [sum + esi], al dec esi loop add_loop mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;telephone call kernel mov edx,five ;message length mov ecx,sum ;message to write mov ebx,ane ;file descriptor (stdout) mov eax,4 ;system phone call number (sys_write) int 0x80 ;call kernel mov eax,1 ;system call number (sys_exit) int 0x80 ;telephone call kernel section .data msg db 'The Sum is:',0xa len equ $ - msg num1 db '12345' num2 db '23456' sum db ' '
When the above code is compiled and executed, it produces the post-obit result −
The Sum is: 35801
Useful Video Courses
Video
Video
Source: https://www.tutorialspoint.com/assembly_programming/assembly_numbers.htm
Posted by: hullfurepought.blogspot.com
0 Response to "How To Move A Decimal Value Into A Register In Arm"
Post a Comment