Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
;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