;Author: Bryan Poole ;Date: 4/2/14 ;Description: prints a string x times and orders three numbers
[SECTION .text] ;Section containing code extern printf ;tells the compiler to reference the C function library for printf extern scanf ;tells the compiler to reference the C function library for scanf extern getchar ;tells the compiler to reference the C function library for getchar global main ;Required so linker can find the entry point
main: push ebp ;push value in base pointer to stack mov ebp, esp ;move the stack pointer value into the base pointer register
push ebx ;push the value in the base address reg to the stack push esi ;push the value in the source index reg to the stack push edi ;push the value in the destination index reg to the stack
push dword name ;pushes the address of the string name call printf ;prints the string name to the screen add esp, 4 ;adds the value of 4 to the stack pointer
push dword prompt1 ;pushes the address of the string call printf ;prints the string name to the screen add esp, 4 ;adds the value of 4 to the stack pointer
push dword word1 ;pushes address of the string buffer word push dword inputstr ;pushes the address of the input format string input call scanf ;scans in an integer value from the keyboard add esp, 8 ;adds 8 to stack pointer
call getchar ;cleans up input string
push dword prompt2 ;pushes the address of the string call printf ;prints the string name to the screen add esp, 4 ;adds the value of 4 to the stack pointer
push dword num1 ;pushes address of the integer buffer num1 push dword input ;pushes the address of the input format string input call scanf ;scans in an integer value from the keyboard add esp, 8 ;adds 8 to stack pointer
call getchar ;cleans up input string
mov ecx, [num1] ;move value of num1 to ecx
loop_start: push ecx ;push counter
push dword word1 ;push word push dword out1 ;push output call printf ;print add esp, 8 ;add 8 to esp
pop ecx ;pop counter loop loop_start ;loop
push dword blank ;push address of string call printf ;print string add esp, 4 ;add 4 to stack pointer
push dword prompt3 ;pushes the address of the string call printf ;prints the string name to the screen add esp, 4 ;adds the value of 4 to the stack pointer
push dword num4 ;pushes address of the integer buffer num1 push dword num2 ;pushes address of the integer buffer num1 push dword num3 ;pushes address of the integer buffer num1 push dword input2 ;pushes the address of the input format string input call scanf ;scans in an integer value from the keyboard add esp, 12 ;adds 16 to stack pointer
call getchar ;cleans up input string
mov eax, [num2] ;moves first num mov ebx, [num3] ;moves second num mov ecx, [num4] ;moves third num
endj: push dword out2 ;pushes the address of the string call printf ;prints the string name to the screen add esp, 16 ;adds the value of 4 to the stack pointer
push dword success ;push the address of string call printf ;prints string add esp, 4 ;adds 4 to the stack pointer
pop edi ;now we restore the original values pop esi pop ebx mov esp, ebp pop ebp ret
[SECTION .data] ;section containing initialized data
name db "Bryan Poole",10,0 ;defines name to be the string "Bryan" prompt1 db "Please enter a word: ",0 ;string to ask for a word prompt2 db "Please enter number: ",0 ;string to ask for number blank db "",10,0 ;blank line prompt3 db "Please enter three more numbers: ",0 ;string to ask for number input db "%d\n" ;end of line needed to advance cursor in scanf input2 db "%d%d%d\n" ;end of line needed to advance cursor in scanf inputstr db "%s\n" ;end of line needed to advance cursor in scanf out1 db "%s",10,0 ;string to out put word out2 db "Your numbers in ascending order are: %d, %d, %d:",10,0 ;prints numbers
success db "***Succesful Program Termination***",10,0 ;string to output end
[SECTION .bss] ;section containing uninitialized data
num1 resd 1 ;reserves space for number value from input num2 resd 1 ;reserves space for number value from input num3 resd 1 ;reserves space for number value from input num4 resd 1 ;reserves space for number value from input word1 resd 1 ;reserves space for string value from input