Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a.asm ####################################################################################################################################
- bits 32
- global start,r
- extern exit,printf,maxBytes
- import exit msvcrt.dll
- import printf msvcrt.dll
- segment data use32 class=data
- s dd 1234A678h,12345678h,1AC3B47Dh,0FEDC9876h
- lenS equ ($-s)/4
- r times lenS db 0
- d resd 1
- sum resd 1
- pf db "%Xh ",0
- pf2 db `\nThe sum (signed) sum of these bytes is %d\n`,0
- segment code use32 class=code
- start:
- ;maxBytes(s,lenS)
- push lenS
- push s
- call maxBytes
- add ESP,4*2
- ;this will return in eax the sum of the max bytes
- mov [sum],EAX
- CLD
- mov ESI,s
- mov EDI,0
- ; now print these bytes using the damn string of byte ranks
- ; that was built using the function from b.asm
- printBytes:
- LODSD ; EAX = ESI , ESI+=4
- mov [d],EAX ; put in [d] the current dword
- mov EBX,d ; put its offset in EBX to use the amazing XLAT
- mov AL,4 ; because of little endian
- sub AL,[r+EDI] ; now we get the good position
- XLAT ; AL := [d+AL]
- movzx EAX,AL
- ;now print the byte extracted from the current dword
- push EAX
- push pf
- call [printf]
- add ESP,4*2
- inc EDI
- cmp EDI,lenS
- jb printBytes
- ;print(pf,sum)
- push dword[sum]
- push pf2
- call [printf]
- add ESP,4*2
- jmp $ ; keeps your compiled exe open
- push dword 0
- call [exit]
- b.asm ##################################################################################################################################
- bits 32
- extern r
- global maxBytes
- segment data use32 class=data
- max resb 1 ; used to calculate the max byte
- d resd 1 ; local variable used by the function
- segment code use32 class=code
- maxBytes:
- mov ESI, [ESP+4] ; s parameter
- mov ECX, [ESP+8] ; lenS parameter
- mov EBX,0 ;initialize sum
- mov EDI,r ;string from a.asm that will store the max bytes ranks
- CLD
- parseS:
- push ECX ; save ECX cuz we gonna need it l8r
- LODSD ; put in EAX the current dword
- mov [d],EAX
- mov ECX,0 ; this will be our byte index
- mov AL,1 ; initialize rank
- mov [max],CL ; initialize max byte
- findMax:
- mov DL,[d+ECX]
- cmp DL,[max]
- jbe next
- mov [max],DL
- mov AL,4 ; we have to do this shit bc little endian
- sub AL,CL ; now we have the rank in AL
- next:
- inc ECX
- cmp ECX,4 ; check if we interated over all the 4 bytes of the dword
- jb findMax
- STOSB ; in AL we have the rank of the max byte
- movsx EAX,byte[max] ; in [max] we have the max byte
- add EBX,EAX ; add the signed byte to the sum
- pop ECX ; restore the saved ECX
- loop parseS
- mov EAX,EBX ; ret the signed sum in EAX
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement