abc Asembler - elektronski priručnik
XIV dio Brojevi
ASCII reprezentacija
U ASCII reprezentaciji, decimalni brojevi se spremaju kao stringovi ASCII karaktera. Na primjer, decimalna vrijednost 1234 je spremljena kao:
31 32 33 34H
Gdje je, 31H ASCII vrijednost za 1, 32H je ASCII vrijednost za 2, itd. Postoje 4 instrukcije za procesiranje brojeva u ASCII reprezentaciji:
- AAA - ASCII Adjust After Addition
- AAS - ASCII Adjust After Subtraction
- AAM - ASCII Adjust After Multiplication
- AAD - ASCII Adjust Before Division
Ove instrukcije ne uzimaju nikakve operande i pretpostavljaju da će traženi operand biti u AL registru.
Sljedeći primjer koristi AAS instrukciju da demonstrira ovaj koncept:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
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, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov edx, 1 ;message length
mov ecx, res ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Rezultat je:', 0xa
len equ $ - msg
section .bss
res resb 1
Kada se gore navedeni kod kompajlira i izvrši, on će proizvesti sljedeći rezultat:
Rezultat je:
6
Brojevi < Index > BCD reprezentacija
|
 |