Lesson 5 of 15
Addition & Subtraction
Addition and Subtraction
The two most basic arithmetic instructions:
add dst, src ; dst = dst + src
sub dst, src ; dst = dst - src
Both update the flags register (ZF, SF, CF, OF) based on the result.
Increment and Decrement
inc rax ; rax = rax + 1
dec rax ; rax = rax - 1
NEG: Two's Complement Negation
neg rax ; rax = -rax
Computing and Printing a Number
To print a number, you need to convert it to ASCII digits. The simplest approach for single digits is to add 48 (ASCII '0'):
mov rax, 7 ; the number 7
add rax, 48 ; convert to ASCII '7' (55)
For this exercise, we will work with single-digit results.
Your Task
Compute the following and print each result as a digit followed by a newline:
- 3 + 4 = 7
- 9 - 5 = 4
- Start with 0, increment 6 times = 6
Print: "7\n4\n6\n"
x86_64 runtime loading...
Loading...
Click "Run" to execute your code.