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/arrayPrint.asm
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (41 sloc)
1.14 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 to declare array and use push and pop to print contents | |
section .data | |
global x | |
x: | |
db 'l' | |
db 'h' | |
db 'h' | |
db 'h' | |
db 'h' | |
letter: | |
db 0 | |
section .text | |
global _start ;must be declared for linker (ld) | |
_start: | |
mov rax,5 ;number bytes to be summed | |
mov rbx,0 ;EBX will store the sum | |
mov rcx, x ;ECX will point to the current element to be summed | |
top: | |
mov rbx, [rcx] | |
mov [letter],rbx ; move rbx into a variable letter | |
push rax ; push rax on stack | |
push rbx ; push rbx on stack | |
push rcx ; push rcx on stack | |
call display ; print letter | |
pop rcx ; get back from stack | |
pop rbx ; get back from stack | |
pop rax ; get back from stack | |
add rcx,1 ;move pointer to next element | |
dec rax ;decrement counter | |
jnz top ;if counter not 0, then loop again | |
call done ; end program | |
display: | |
mov edx,1 ;message length | |
mov ecx, letter ;message to write | |
mov ebx, 1 ;file descriptor (stdout) | |
mov eax, 4 ;system call number (sys_write) | |
int 0x80 ;call kernel | |
ret | |
done: | |
mov eax, 1 ;system call number (sys_exit) | |
int 0x80 ;call kernel |