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
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


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 Laughing


Last edited by LocoDelAssembly on 02 Aug 2007, 15:24; edited 1 time in total
Post 02 Aug 2007, 15:23
View user's profile Send private message Reply with quote
dead_body



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

Or rename thread.
Post 02 Aug 2007, 15:23
View user's profile Send private message Reply with quote
0.1



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

_________________
Code:
 o__=-
 )
(\
 /\  
    
Post 03 Aug 2007, 06:20
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2145
Location: Estonia
Madis731
nobody's got 32-bit OSs these days Razz 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
add al,49h
;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
    


same for aad...


MACROS:
=======
AAA:
Code:
;Code is intentionally long to make the internals clear
;displaying (al1+al2)/10,(al1+al2) mod 10 would explain anything Very Happy
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
Post 03 Aug 2007, 08:41
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Thanks Madis for AAA example!
Please give examples of AAS, AAD and AAM also.
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
Post 03 Aug 2007, 08:51
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Code:
mov ax,99h
add ax,99h
aaa    
what is ax now ?
Post 03 Aug 2007, 08:56
View user's profile Send private message Reply with quote
0.1



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

Or rename thread.

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

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

_________________
Code:
 o__=-
 )
(\
 /\  
    
Post 03 Aug 2007, 08:58
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2145
Location: Estonia
Madis731
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
Post 03 Aug 2007, 09:28
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Thanks for your time Madis!
Post 03 Aug 2007, 09:36
View user's profile Send private message Reply with quote
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__=-
 )
(\
 /\  
    
Post 03 Aug 2007, 10:03
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2145
Location: Estonia
Madis731
Update
Post 03 Aug 2007, 12:07
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
Thanks Madis!


Last edited by 0.1 on 17 Sep 2007, 05:40; edited 1 time in total
Post 03 Aug 2007, 12:25
View user's profile Send private message Reply with quote
0.1



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

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


Last edited by 0.1 on 17 Sep 2007, 05:44; edited 4 times in total
Post 31 Aug 2007, 13:19
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


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:
  call    readInt
  test    eax, eax
  jz      .print

  mov     edx, tree
  call    insert
  jmp     main

.print:
  push    message
  call    printf
  add     esp, 4

  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
  add     esp, 4

  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
readInt:
  push    eax   ; Reserves space to store the integer

  push    esp   ; Stores a pointer to the space reserved above
  push    .fmt
  call    scanf
  add     esp, 4*2

  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
  add     esp, 8
  ret
.fmt      db "%d", 10, 0
    

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


Last edited by LocoDelAssembly on 05 May 2008, 14:41; edited 1 time in total
Post 31 Aug 2007, 13:56
View user's profile Send private message Reply with quote
penang



Joined: 01 Oct 2004
Posts: 59
penang
Por favor, donde el translaciones?
Post 05 May 2008, 10:10
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Done
Post 05 May 2008, 14:43
View user's profile Send private message Reply with quote
penang



Joined: 01 Oct 2004
Posts: 59
penang
Muchos Gracias !!
Post 05 May 2008, 15:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.