Assembly Language Crash Course 5
Okay, the series is back.
Sorry for the shortness of this one. Just lost motivation. Upvote for longer ones :D
So let's start already.
Section 10: while loop.
Consider the code below
while:
add eax, 1
cmp eax, 5
jl while
ret
This is a while loop!
So at the end of the code we want we do a cmp
and then do a conditional jump back, if that jump is not true we ret
.
Section 11: Better print
Consider the code below:
section .text
global _start
_start:
mov si, msg
call printf
printf:
pusha
loop:
mov al, [si]
cmp al, 0
jne print_char
popa
ret
print_char:
mov ah, 0x0e
int 0x10
add si, 1
jmp loop
section .data
msg db, "Hello World", 0x0a, 0
That was a lot of code! Let's break it down.
ah
, si
, and al
are more registers measuring 16, 8, and 8 bit in size, respectively.
pusha
pushes everything to the stack.
popa
pops everything from the stack.
int 0x10
is the BIOS interrupt to pint a single character stored in `al to the screen.
And what we are doing is looping until we find a 0, that is why we have the , 0
an=t the end of our string in the data section.
So you push the db
to si
and call
printf
.
Anyway.
Feedback, upvote.
okay wuru has a alt
no i dont @HahaYes
@HahaYes Link?
wuru do you have two alts? This is pretty suspicous tbh
@Wuru hmmmmm
You don't really use real mode assembly unless you're writing a bootloader
16, 8, and 8
You were intending to say that si
and al
are both 8 bit registers, right?
Syntax error on line 20 of section 11 - {msg db, "Hello ...} -- comma breaks the code after "db". Also, in attempting to run this program, on various different environments I get:
main.o: In function _start':
main.asm:(.text+0x2): relocation truncated to fit: R_386_16 against
.data'
In which case, my assumption was that it was attempting to truncate the message which would be 16 bits into si which is only 8: so I tried changing the registers from using si to esi, but I get the error:
timeout: the monitored command dumped core
sh: line 1: 19660 Segmentation fault timeout 10s demo
So far I haven't found a solution.
@danielathome19 run it in QEMU
Randomly saw this in talk :) I'll find the previous and learn from it. Which version of Assembly does this use? I've been wanting to learn ARM Assembly
It uses x86 assembly :D intel syntax. @MesyetiIsTaken
Ok :D @Wuru
Yay, i need this REALLY
print_char:
mov ah, 0x0e
int 0x10
add si, 1
jmp str_loop
str_loop doesn’t seem to exist. Did you mean loop?
that is mass farming for him
how did you just gain like 300 cycles
@Wuru you have gained over 300 cycles
@Wuru slightly sus of the account fallenangel13
@HahaYes If you notice it's not just @FallenAngel13 there is also @SarahHeisnoran
@johnstev111 oh yeah
@HahaYes this is something i experience every day.
@Jakman lol, jakman nice logo
@HahaYes thx. Do you know what it is?
@Jakman I dunno
@Jakman I assume it is a greek symbol
@HahaYes it is the lambda symbol for the functional programming paradigm. Also it is the greek letter lambda.
@HahaYes what do you say that you and i make a file corruptor?
@Jakman ummm no. Also it is 10:30 pm at my end
@HahaYes thats cool. It's 9:30 pm here.
@Jakman but I mean, you can share it with me
@Jakman share it with me
@HahaYes alright cool. I'll make an engine real quick and when i get no errors and less than 50 warnings ill share it
@HahaYes alright. you can always ask questions as I have lots of time at my hands
@Jakman I know! Tis' scheme.
wait wha
@Wuru Who's alt are you
nobody? Im a main account. @johnstev111
Wonderful!
Great!
Have you assembled your next tutorial??
very corny joke. @DynamicSquid
@Wuru sorry
LOL @DynamicSquid
Lul @DynamicSquid