Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .text
- %include "cgi86/linuxhlp.asm"
- global _start
- _start:
- push edi
- mov eax, 5
- ;call int2Str
- mov [sHeader+1], byte 3;
- mov ecx, edi ; set str ptr to ecx
- mov edx, eax ; set length of string to edx
- pop edi
- mov eax, write ; Send the header to the server for HTML data
- mov ebx, stdout
- ;int 80h
- mov eax, exit ; Terminate program
- mov ebx, 00h ; Exit code 0
- int 80h
- ; ------------------------------------------
- ; Converts a 32bit integer value to a string
- ;
- ; input:
- ; eax = input value
- ;
- ; returns:
- ; eax = length of string
- ; esi = address of null-terminated string
- ;
- ; trashes: none
- int2Str:
- push ebx
- push ecx
- push edx
- mov ecx, 1 ; number of digits in string
- mov ebx, 10 ; Divide by 10 each time
- mov edi, tmpStr+8
- .nextDigit:
- cmp eax, 10 ; If eax < 10, we've found all digits
- jb .finished
- xor edx, edx ; Clear edx every time (we're not dividing 64 bit val)
- div ebx ; Divide value by 10
- add dl, '0' ; Remainder in edx is a digit to store
- mov [edi], dl
- dec edi ; Adjust ptr to draw next char
- inc ecx ; add one char to counter
- jmp .nextDigit ; Keep looping until we've found all digits
- .finished:
- add al, '0' ; The final digit is stored in eax
- ;mov [edi], al
- mov eax, ecx ; return length of string in eax
- pop edx
- pop ecx
- pop ebx
- ret
- section .data:
- tmpStr: DB "4294967296", 00h ; Largest possible number we'll return
- sHeader: db "Content-Type: text/html", 10, 10
- headerLen: equ $ - sHeader
- sMessage: db "<H1>Hello Internet from x86 assembly!!</H1>", 13, 10
- msgLen: equ $ - sMessage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement