Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2. %include "cgi86/linuxhlp.asm"
  3.  
  4. global _start
  5.  
  6. _start:
  7.     push edi
  8.     mov eax, 5
  9.     ;call int2Str
  10.     mov [sHeader+1], byte 3;
  11.  
  12.     mov ecx, edi  ; set str ptr to ecx
  13.     mov edx, eax  ; set length of string to edx
  14.     pop edi
  15.  
  16.     mov eax, write    ; Send the header to the server for HTML data
  17.     mov ebx, stdout
  18.     ;int 80h
  19.  
  20.     mov eax, exit  ; Terminate program
  21.     mov ebx, 00h   ; Exit code 0
  22.     int 80h
  23.  
  24. ; ------------------------------------------
  25. ; Converts a 32bit integer value to a string
  26. ;
  27. ; input:
  28. ;    eax = input value
  29. ;
  30. ; returns:
  31. ;    eax = length of string
  32. ;    esi = address of null-terminated string
  33. ;
  34. ; trashes: none
  35. int2Str:
  36.     push ebx
  37.     push ecx
  38.     push edx
  39.  
  40.     mov ecx, 1      ; number of digits in string
  41.     mov ebx, 10     ; Divide by 10 each time
  42.     mov edi, tmpStr+8
  43.  
  44.   .nextDigit:
  45.     cmp eax, 10     ; If eax < 10, we've found all digits
  46.     jb .finished
  47.  
  48.     xor edx, edx    ; Clear edx every time (we're not dividing 64 bit val)
  49.     div ebx         ; Divide value by 10
  50.  
  51.     add dl, '0'     ; Remainder in edx is a digit to store
  52.     mov [edi], dl
  53.  
  54.     dec edi         ; Adjust ptr to draw next char
  55.     inc ecx         ; add one char to counter
  56.     jmp .nextDigit ; Keep looping until we've found all digits
  57.  
  58.   .finished:
  59.     add al, '0'     ; The final digit is stored in eax
  60.     ;mov [edi], al
  61.  
  62.     mov eax, ecx    ; return length of string in eax
  63.  
  64.     pop edx
  65.     pop ecx
  66.     pop ebx
  67.     ret
  68.  
  69. section .data:
  70.   tmpStr: DB "4294967296", 00h ; Largest possible number we'll return
  71.  
  72. sHeader: db "Content-Type: text/html", 10, 10
  73. headerLen: equ $ - sHeader
  74.  
  75. sMessage: db "<H1>Hello Internet from x86 assembly!!</H1>", 13, 10
  76. msgLen: equ $ - sMessage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement