flat assembler
Message board for the users of flat assembler.

Index > Main > New book: Programming from Scratch

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Melissa



Joined: 12 Apr 2012
Posts: 125
Melissa
Learning programming, it is very important not to use computer to check results, rather paper and pencil and imagine
what result will be. In this way you donćt need debugger and learn how to program.
Post 18 Sep 2021, 11:46
View user's profile Send private message Reply with quote
Melissa



Joined: 12 Apr 2012
Posts: 125
Melissa
Melissa wrote:
Learning programming, it is very important not to use computer to check results, rather paper and pencil and imagine
what result will be. In this way you donćt need debugger and learn how to program.


btw site doesnćt allow access to book in trial period. I have tried to pay doesnćt work
either. Perhaps they have legal issues?
Post 18 Sep 2021, 13:12
View user's profile Send private message Reply with quote
Melissa



Joined: 12 Apr 2012
Posts: 125
Melissa
mine fizzbuzz:P
Code:
format elf64 executable 3
include 'import64.inc'

interpreter '/lib64/ld-linux-x86-64.so.2'
needed 'libc.so.6'
import  exit,printf
FNUM equ 40000000
segment executable
entry $
        xor ebx,ebx
.L0:
        vpmovzxdq ymm0,[arr+ebx] ; zero extend to quad word
        vpmuludq ymm1,ymm0,yword[cnst3] ; division by multiply and shift
        vpsrlq ymm2,ymm1,33
        vpmuludq ymm3,ymm2,yword[three] ; multiply
        vpcmpeqd ymm4,ymm0,ymm3 ; see difference
        vpaddd ymm4,ymm0,ymm4 ; add resulting mask which is -1 if equal
        vpshufb ymm4,ymm4,yword[smask] ; mov dwords in right place
        vpermq ymm4,ymm4,1000b ; mov 4 dwords in place

        vpmuludq ymm1,ymm0,yword[cnst5]
        vpsrlq ymm2,ymm1,34
        vpmuludq ymm3,ymm2,yword[five]
        vpcmpeqd ymm5,ymm0,ymm3
        vpaddd ymm5,ymm5,ymm5 ; make that in -2
        vpshufb ymm5,ymm5,yword[smask]
        vpermq ymm5,ymm5,1000b

        vpaddd ymm4,ymm5,ymm4 ; if both matches then -3 would be added

        vmovdqa [arr+ebx],xmm4
        add ebx,16
        cmp ebx,FNUM*4
        jl .L0
        xor ebx,ebx
.L1:
        mov r8,fizzbuzz
        mov r9,fizz
        mov r10,buzz
        mov edx,[arr+rbx*4]
        lea esi,[rbx+1]
        mov rdi,fmt
        sub esi,edx
        cmp esi,3 ; if difference is 3 then both matches
        cmove rdi,r8
        cmp esi,2 ; buzz matches
        cmove rdi,r10
        cmp esi,1 ; fizz matches
        cmove rdi,r9
        lea rsi,[rbx+1]
        xor eax,eax
        call [printf]
        inc ebx
        cmp ebx,100
        jl .L1
        xor edi,edi
.exit:
        call [exit]

segment writeable
align 16
arr: times FNUM dd % ; initialize 1..100
align 32
cnst3 dq 4 dup(2863311531) ; required shift 33
three dq 4 dup(3)
cnst5 dq 4 dup(3435973837) ; required shift 34
five  dq 4 dup(5)
smask db 0,1,2,3
      db 8,9,10,11
      times 4 db -128
      times 4 db -128
      db 0,1,2,3
      db 8,9,10,11
      times 4 db -128
      times 4 db -128

fmt db '%4d %d',0xa,0
fizz db '%4d fizz',0xa,0
buzz db '%4d buzz',0xa,0
fizzbuzz db '%4d fizzbuzz',0xa,0
    
Post 18 Sep 2021, 13:34
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

< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.