I am making a simple program to print “Hello, world!” in hex ASCII characters.
Here is my code:
SECTION .DATA
msg db 'Printing Hello world in ASCII values: ', 0
msglen EQU $-msg
char1 db 064h ; 'd' character
char2 db 06Ch ; 'l' character
char3 db 072h ; 'r'
char4 db 06Fh ; 'o'
char5 db 077h ; 'w'
char6 db 020h ; (space)
char7 db 06Fh ; 'o'
char8 db 06Ch ; 'l'
char9 db 06Ch ; 'l'
char10 db 065h ; 'e'
char11 db 048h ; 'H'
SECTION .bss
SECTION .text
GLOBAL _start:
_start:
nop
mov esi, 0
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msglen
int 80h
; printing 'H'
mov eax, 4
mov ebx, 1
mov ecx, char11
mov edx, 1
int 80h
; printing 'e'
mov eax, 4
mov ebx, 1
mov ecx, char10
mov edx, 1
int 80h
; printing 'l'
mov eax, 4
mov ebx, 1
mov ecx, char9
mov edx, 1
int 80h
; printing 'l'
mov eax, 4
mov ebx, 1
mov ecx, char8
mov edx, 1
int 80h
; printing 'o'
mov eax, 4
mov ebx, 1
mov ecx, char7
mov edx, 1
int 80h
; printing space
mov eax, 4
mov ebx, 1
mov ecx, char6
mov edx, 1
int 80h
; printing 'w'
mov eax, 4
mov ebx, 1
mov ecx, char5
mov edx, 1
int 80h
; printing 'o'
mov eax, 4
mov ebx, 1
mov ecx, char4
mov edx, 1
int 80h
; printing 'r'
mov eax, 4
mov ebx, 1
mov ecx, char3
mov edx, 1
int 80h
; printing 'l'
mov eax, 4
mov ebx, 1
mov ecx, char2
mov edx, 1
int 80h
; printing 'd'
mov eax, 4
mov ebx, 1
mov ecx, char1
mov edx, 1
int 80h
; end
mov eax, 1
mov ebx, 0
int 80h
MY QUESTION:
How can I do something like this:
loop:
mov eax, 4
mov ebx, 1
mov ecx, char[incremented variable]
mov edx, 1
int 80h
inc (incremented variable)
jmp loop
What I mean is how can I have a variable and an incrementing counter be read as one variable?
Thanks in advance.
You’d need to make an array out for your string, the same way
msgis declared, the load the pointer to that string, dereference to get that character, check if its 0, break if so, else print and increment the pointer.eg: (MASM syntax, sorry)
Just noticed that your title states x86-64, but your code (and my code), is plain x86, if you are actually wanting x64 code, the ABI for the syscall’s changes a bit, but the rest is pretty much the same.