Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Guessuing_Game/quotes.asm
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
101 lines (87 sloc)
3.36 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; assembly code for print a list of quotes of variable length strings | |
;This code uses an array of quotes and array of quote lengths | |
section .data | |
;Welcome to list of quotes message | |
;Welcome message size | |
welcome db "Welcome to List of quotes", 10 | |
welcomeLen equ $-welcome | |
;Same as endl in C++ | |
cr db 10 | |
; The quotes and quote lengths for the arrays | |
Quote1 db "If life were predictable it would cease to be life, and be without flavor." | |
Quote1len equ $-Quote1 | |
Quote2 db "Life is what happens when you're busy making other plans. " | |
Quote2len equ $-Quote2 | |
Quote3 db "Always remember that you are absolutely unique. Just like everyone else. " | |
Quote3len equ $-Quote3 | |
Quote4 db "The future belongs to those who believe in the beauty of their dreams. " | |
Quote4len equ $-Quote4 | |
Quote5 db "You will face many defeats in life, but never let yourself be defeated. " | |
Quote5len equ $-Quote5 | |
;the array we use to point to the quotes | |
listQuotes: | |
dq Quote1 ; the pointer to the quotes are stored in 8 bytes | |
dq Quote2 | |
dq Quote3 | |
dq Quote4 | |
dq Quote5 | |
;the array we use to point to the quote lengths | |
listQLen: | |
dq Quote1len ; the pointer to the quote lengths are stored in 8 bytes | |
dq Quote2len | |
dq Quote3len | |
dq Quote4len | |
dq Quote5len | |
segment .bss | |
section .text | |
global _start ;must be declared for linker (ld) | |
_start: | |
call displayWelcome ; call function for welcome message | |
call newLine ; call function for newline | |
mov rax,5 ;number of quotes to loop through | |
mov r8, listQuotes ; point to first quote | |
Mov r9, listQLen ; point to the length of first quote | |
; main function to display the quotes | |
top: | |
push rax ; push rax on stack (The number of quote we are dealing with) | |
call displayQuote ; function to display quote | |
call newLine ; function to create a newline | |
pop rax ; get where we are in the list of quotes back from the stack | |
add r8,8 ; add on 8 bytes as using dq data type | |
add r9,8 ; add on 8 bytes as using dq data type | |
dec rax ;decrement counter so going down list of quotes | |
jnz top ;if counter not 0, then loop again as not at end of list of quotes | |
call done ; end program | |
; Function to create a New line like endl in C++ | |
newLine: | |
mov eax,4 ; Put 4 in eax register into which is system | |
;call for write (sys_write) | |
mov ebx,1 ; Put 1 in ebx register which is the standard | |
; output to the screen | |
mov ecx, cr ; Put the newline value into ecx register | |
mov edx, 1 ; Put the length of the newline value into edx | |
; register | |
int 80h ; Call the kernel with interrupt to check the | |
; registers and perform the action of moving to | |
; the next line like endl in c++ | |
ret ; return to previous position in code | |
;Function to display welcome to game message | |
displayWelcome: | |
mov edx,welcomeLen ;message length | |
mov ecx, welcome ;message to write | |
mov ebx, 1 ;file descriptor (stdout) | |
mov eax, 4 ;system call number (sys_write) | |
int 0x80 ;call kernel | |
ret | |
;Function to display quotes | |
displayQuote: | |
mov edx, [r9] ;message length content of register r9 | |
mov ecx, [r8];message to write content of register r8 | |
mov ebx, 1 ;file descriptor (stdout) | |
mov eax, 4 ;system call number (sys_write) | |
int 0x80 ;call kernel | |
ret | |
; Function to end the program | |
done: | |
mov eax, 1 ;system call number (sys_exit) | |
int 0x80 ;call kernel | |