flat assembler
Message board for the users of flat assembler.

 Index > Projects and Ideas > Programmes and Examples for fasm Goto page Previous  1, 2, 3, 4
Author
LocoDelAssembly

Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I try to explain how Madis' non-SSE version works
Code:
```; Copies AL to EAX:8, EAX:16, EAX:24
; How?
; Lets change the magic constant into an equivalent expression
; \$01010101 = (1 shr 24) + (1 shr 16) + (1 shr 8 ) + (1 shr 0)
; Now, you see what happens? The resulting operation is this
; EBX = AL*(1 shr 24) + AL*(1 shr 16) + AL*(1 shr 8 ) + AL*(1 shr 0)
; NOTE: Actually the expression above is valid if and only if all the register except AL was cleared
imul    ebx,eax,01010101h

; Now, by XORing we get a zero value if and only if the byte has the same value as the vowel
xor     ebx,'aeio'
mov     edx,ebx

; Vowels will be \$FF ----------------------------------------+
not     ebx                                        ; |
; |
; The bytes that was vowels will have higher bit set to 1  ; |
sub     edx,01010101h                              ; |
; |
; Now lets keep high bits only ------------------------------+
and     ebx,80808080h

; And now if one of the high bits was set then the char was one of the vowels
and     ebx,edx ; Can be "test" instruction here
```

I hope I'd explain it correctly but if I not then Madis will tell

Last edited by LocoDelAssembly on 02 Aug 2007, 15:24; edited 1 time in total
02 Aug 2007, 15:23

Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
please write not procedures, but examples.

02 Aug 2007, 15:23
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Can someone please post examples of AAA, AAS, AAD and AAM instructions.

_________________
Code:
``` o__=-
)
(\
/\
```
03 Aug 2007, 06:20

Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
nobody's got 32-bit OSs these days so its rather obsolete. I'm starting to hate the examples in 16-bit mode, because on 64-bit they're not supported :S

Anyways, I didn't debug this because I've only got FDBG so here:
AAA:
Code:
```mov al,36h
;Here the al register is 7Fh but in BCD it should be 85
aaa
;That is where its modified so that last digit is 5 and 3+4+carry=8
;al=85h
```

same for aas

AAM:
Code:
```mov  al,6h ;ONLY one digit
imul al,9h
;Here the al register is 36h but in BCD it should be 54
aam
;That is where its modified so that last digit is 4 and first is 5
;ax=54
```

MACROS:
=======
AAA:
Code:
```;Code is intentionally long to make the internals clear
;displaying (al1+al2)/10,(al1+al2) mod 10 would explain anything
al1=9
al2=6
myAL=al1+al2 ;0Fh
myAH=0
af=(myAL shr 4) and 1 ;Auxiliary flag for nibble carrys

if ((myAL and 0Fh)>9) | af=1
myAL=(myAL+6) and 0Fh
myAH=myAH+1
end if
display "AX=",myAH+30h,myAL+30h
```

AAM:
Code:
```al1=9
al2=6
myAL=al1*al2 ;36h

myAH = myAL / 10;
myAL = myAL MOD 10;
display "AX=",myAH+30h,myAL+30h
;Displays 54 for 6*9
```

AAD: (This is the only one that is BEFORE the operation itself)
Code:
```;0609h => 69h
ah1=6
al1=9 ;This is 69 in unpacked form

al2=7

myAL=ah1*10+al1
myAH=0

display "AX=",myAL/10+30h,myAL mod 10+30h,'h'
```

Last edited by Madis731 on 03 Aug 2007, 10:43; edited 3 times in total
03 Aug 2007, 08:41
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Thanks.

PS: Thanks for all your help!

_________________
Code:
``` o__=-
)
(\
/\
```

Last edited by 0.1 on 03 Aug 2007, 10:05; edited 2 times in total
03 Aug 2007, 08:51
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Code:
```mov ax,99h
aaa    ```
what is ax now ?
03 Aug 2007, 08:56
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
please write not procedures, but examples.

It's Programs and Examples so examples are ok to post here.

PS: If i'm wrong I hope m will change the title

_________________
Code:
``` o__=-
)
(\
/\
```
03 Aug 2007, 08:58

Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
I will update my post if I get more info, but I read the AAA description a bit off. The only part of the register that is concerned is AL so no 16-bit calculations for you :S http://board.flatassembler.net/topic.php?p=60769#60760
03 Aug 2007, 09:28
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
03 Aug 2007, 09:36
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
If someone else is also interested in AAA,AAS,AAD and AAM then I
will suggest using DEBUG under DOS/Windows.
I'm also using it to learn these instructions!

PS: Ofcourse you can also use Madis's macro (see above)!

_________________
Code:
``` o__=-
)
(\
/\
```
03 Aug 2007, 10:03

Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Update
03 Aug 2007, 12:07
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1

Last edited by 0.1 on 17 Sep 2007, 05:40; edited 1 time in total
03 Aug 2007, 12:25
0.1

Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
A binary tree example that is not here now

Yeh meri do sauvi post hai
.tsop htderdnuh owt ym si sihT

Last edited by 0.1 on 17 Sep 2007, 05:44; edited 4 times in total
31 Aug 2007, 13:19
LocoDelAssembly

Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I can't check you code now, I leave here with something I did to show to some friends
Code:
```; Make the executable in the following way:

; fasm tree.asm
; gcc -m32 tree.o -o tree
; rm tree.o (OPTIONAL)
; strip tree (OPTIONAL, reduce executable's size)
; PROGRAM Tree;
format ELF

; TYPE
struc TTree
{
.:
.left    dd ?
.right    dd ?
; DON'T CHANGE THE POSITION OF THE FIELDS ABOVE
.datum   dd ?

sizeof.#. = \$ - .
}
; To be able to use the structure without associating it to a variable
virtual at 0
TTree TTree
end virtual

; VAR
section '.bss' writable
tree dd 0

section '.text' executable
extrn   printf
extrn   scanf
extrn   malloc
extrn   exit

public  main
; BEGIN
main:
test    eax, eax
jz      .print

mov     edx, tree
call    insert
jmp     main

.print:
push    message
call    printf

mov     eax, tree
call    printTree

xor     eax, eax
ret
message   db 10, "In-order print:", 10, 0

; #### TREE PROCEDURES
insert: ; EAX = datum ; EDX = var ^TTree
mov     ecx, [edx]
test    ecx, ecx
jz      .createNode

xor     edx, edx
cmp     eax, [ecx+TTree.datum]
setge   dl

lea     edx, [ecx+edx*4]
jmp     insert

.createNode:
push    edx
push    eax

push    sizeof.TTree
call    malloc

mov     [eax+TArbol.left], 0
mov     [eax+TArbol.right], 0
pop     [eax+TArbol.datum]

pop     edx
mov     [edx], eax
ret

; ####

printTree: ; EAX = var ^TArbol
mov     eax, [eax]
test    eax, eax
jz      .exit

push    ebx
mov     ebx, eax

call    printTree
mov     eax, [ebx+TTree.datum]
call    writeLnInt

lea     eax, [ebx+4]
call    printTree

pop     ebx

.exit:
ret

; #### I/O PROCEDURES
push    eax   ; Reserves space to store the integer

push    esp   ; Stores a pointer to the space reserved above
push    .fmt
call    scanf

test    eax, eax
jz      .error

pop     eax
ret

.error:
push    .errorStr
call    printf
pop     eax

push    -1
call    exit
.fmt      db "%d", 0
.errorStr db "ERROR: Invalid number", 10, 0

; ####

writeLnInt: ; EAX=integer
push    eax
push    .fmt
call    printf
ret
.fmt      db "%d", 10, 0
```

(I'll edit my post to translate it to English later)
Translated...[/edit]

Last edited by LocoDelAssembly on 05 May 2008, 14:41; edited 1 time in total
31 Aug 2007, 13:56
penang

Joined: 01 Oct 2004
Posts: 59
penang
Por favor, donde el translaciones?
05 May 2008, 10:10
LocoDelAssembly

Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Done
05 May 2008, 14:43
penang

Joined: 01 Oct 2004
Posts: 59
penang
Muchos Gracias !!
05 May 2008, 15:07
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area
Goto page Previous  1, 2, 3, 4

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum