Learn to Code via Tutorials on Repl.it!

← Back to all posts
Assembly Language Crash Course 3
Wuru (585)

Hey.

So part 3 already. Yay!

I cannot thank you guys enough for your support.

Section 6: Conditional Jumps

Consider the code below.

section .text
  global _start
other:
  mov eax, 1
  mov ebx, 0
  int 0x80
_start:
  mov eax, 4
  cmp eax, 3
  jg other

Let's break down the code you may not understand.

The cmp is a keyword indicating that we are doing a comparison

The syntax for cmp is cmp <value/register>, <value/register>

A better way to say it is cmp <a>, <b>.

In which a is being compared to b.

In this case eax is being compared to 3.

This command sets a system flag basically sets a register in the CPU to equal a value of what went on in the comparison.

Then the jg this is a conditional jump, it looks at what the system flag is set to and performs a jump based on that.

There are many types of these conditional jumps. Let's review a few.

  • jg Jump if the flag says greater than
  • jl Jump if the flag says less than
  • jge Jump if the flag says greater than or equal to
  • jle Jump if the flag says less than or equal to
  • je Jump if the flag says equal to
  • jne Jump if the flag says not equal to

As you can see jg is Jump if greater than.

This means that if eax is greater than 3 it will jump.

So basically we have made an if statement.

But if we add more code after the jump it isn't executed.

That we will discuss in the next section.

Section 7: Calls.

Consider the code below.

section .text
  global _start
other:
  mov ebx, 0
  ret
_start:
  call other
  mov eax, 1
  int 0x80

So let's break this down.

call is the same as jmp but it sets a register to be equal to the line number after the call.

ret just returns to that line.

Really simple.

Anyways that's it.

Farewell until part 4!

The usual, feedback and upvotes.

Commentshotnewtop
firefish (308)

@Wuru Why do you spam ping, you do realise it's against the rulles

Wuru (585)

"spam" it has been like 6 days since i last pinged any of you. @johnstev111

eekboi (272)

@Wuru Lets chill out on the mass pings a little bit please.

Highwayman (1367)

Oh yay! @Wuru

Side note I do also think the mass pings are kind of sketchy, but I enjoy the fact that they keep me updated so idk... there’s good and bad parts lol.

SarahHeisnoran (3)

Very good! This should be on top!

HahaYes (1052)

How did you get 100 cycles in a hour

Wuru (585)

@HahaYes @Coder100 and I are looking into it

HahaYes (1052)

@Wuru alright, I was like wow, 100 cycles in a sec?

HahaYes (1052)

@Wuru lol I just lost 25 cycles

HahaYes (1052)

@Wuru I just lost 30 cycles

Wuru (585)

@HahaYes kinda tired tho so ill deal with it tommorow

HahaYes (1052)

@Wuru ok, congrats on 200 cycles I guess.

goalkenhighligh (3)

Thanks for sharing the information it was very helpful for me @HahaYes https://basketball-legends.online

HahaYes (1052)

Oh look, everyone is using the HahaYes cycle squeezer technique, I think I need to write a article about it.

HahaYes (1052)

@Wuru hmmm I will gain so much profit from it. Must do

firefish (308)

@HahaYes w r i t e t h e a r t i c l e a b o u t c y c l e s q u e e z i n g . T h i s i s h a r d t o r e a d i n n i t ?

HahaYes (1052)

@johnstev111 yeah, I will write a article about cycle squeezing

firefish (308)

@Wuru HahaNo is copyrighted by me

HahaYes (1052)

@johnstev111 trying to write the cycle squeezing article

HahaYes (1052)

@johnstev111 yeah, only johnstev111 can use it @Wuru

firefish (308)

@HahaYes ignore all pings until you're done

DynamicSquid (2673)

@HahaYes what's that? "cycle squeezer technique"?

Wuru (585)

@HahaYes im allowed to, 'tis not in the repl.it rules

HahaYes (1052)

@DynamicSquid I just wrote a post on it Squid

HahaYes (1052)

@DynamicSquid Cycle squeezer technique is when you try to get a bunch of cycles by delaying the release of everything, but just put a section of a tutorial at a time, only @CodingCactus , who just gives everything at once.

firefish (308)

@Wuru I copyrighted it though

CodingCactus (2824)

@HahaYes well, I'm not writing a tutorial for myself am I? So I make it as easy to use as I can for the people that want it. Therefore I just put it in all one post so that they just have that page rather than having to go scrambling around repl talk to find the post in the 'series' which will help them with their problem.

I generally find that people doing series in repl talk is just cycle farming, especially if after the series is over, they then post the whole thing combined into one post. It is also a waste of electronic paper to split it up into multiple posts.

HahaYes (1052)

@CodingCactus "waste of electronic paper" oh no save the amasad trees

Wuru (585)

@CodingCactus AHHHH NO THE BITS AND BYTES!

Jakman (377)

@HahaYes thats just a marketing tech called supply and demand. Apple does it well.

Highwayman (1367)

Quick question: don’t ret and call push the instruction point to the stack or something...? I never understood how they could remember the place of the call...

Wuru (585)

@Highwayman yeah, that's why in 16-bit Real mode we do pusha and popa at the start to push and pop everything.

Highwayman (1367)

@Wuru ahh cool cool thanks :)

Highwayman (1367)

UwU yeas! This is so nice! We’re getting to the good stuff!! When do we do stack operations and such?

Wuru (585)

@Highwayman next part we will start with the stack and do some functions.

Highwayman (1367)

@Wuru noice awesome I’m so ready lol. :D

firefish (308)

@HaHaYes do you consent to UwUYes being used?

HahaYes (1052)

@johnstev111 nah I don't like it, I don't really like emoticons

Highwayman (1367)

@HahaYes

But (^ω^)はい

firefish (308)

@HahaYes Ok then, @Highwayman keeps the rights to that.

firefish (308)

@Highwayman the greek letter omega (ω) makes the sound o