CO Lab Manual
Course Page
  • Course Information
    • Welcome
    • Introduction
    • Your Contributions
    • Lab Sessions and Etiquette
    • Team Setup
    • Assumed Prior Knowledge
  • Setup Guides
    • GitHub Repository Setup
    • Technical Setup
      • Windows
      • Linux
      • macOS
    • GitHub SSH Setup
    • Framework Setup
  • Reference Documentation
    • Introduction to the Documentation
    • A Brief History Lesson
    • Syntax (Intel vs. AT&T)
      • Section Exercises
    • Memory
      • Memory Management
      • Section Exercises
    • Registers
      • Section Exercises
    • Instructions
    • Subroutines
      • Calling Subroutines
      • Writing Subroutines
      • Section Exercises
    • Input/Output
      • Printing to the Terminal
      • Reading from the Terminal
      • Section Exercises
    • Programming Constructs
    • Assembler Directives
    • C/C++ vs Assembly
    • Building and Running Programs
    • Address Sanitization
    • A0: A Running Example
  • Assignments
    • Introduction to the Assignments
    • Mandatory Assignments
      • A1: Subroutines and I/O
      • A2: Recursion
    • Extra Assignments
      • A3-a: Fibonacci Calculator
      • A3-b: Fibonacci REPL
      • A4: Diff
      • A5: Printf
      • A6: HPC
      • A7: Bitmap
      • A8: Game
  • Appendix
    • Acknowledgments
    • Rules and Regulations
    • Frequently Asked Questions
    • How to use a Debugger
Powered by GitBook
On this page
  • True or False
  • Multiple Choice
  1. Reference Documentation
  2. Syntax (Intel vs. AT&T)

Section Exercises

True or False

We use the b termination for an instruction to indicate that we access 2 bytes.

False!

The b termination of an instruction, such as movb, indicates that one byte of data is accessed.

We use the q termination for an instruction to indicate that we access 8 bytes.

True!

q stands for "quadword", which means 8 bytes.

subl %eax, %ebx is read like eax - ebx.

False!

The sub instruction subtracts the source operand from the destination operand, so this line would be read as ebx - eax.

In movq %rax, %rbx, rax is the destination and rbx is the source, so we interpret this instruction as rax = rbx.

False!

For a mov instruction, the first operand is the source and the second is the destination, so rax is the source and rbx is the destination. As a result, the instruction is interpreted as rbx = rax.

Multiple Choice

We have some values in rax and rbx. How do you check if their difference (rbx - rax) is smaller than the value 9 in AT&T Assembly?

subq %rax, %rbx 
cmpq %rbx, $9 
jl somelabel

Wrong!

The cmpq instruction is one of the instructions in which the most right element is the on the left side of the comparison, meaning that in this example, the instruction can be interpreted as 9 < rbx.

subq %rax, %rbx 
cmpq $9, %rbx 
jl somelabel

Correct!

subq %rbx, %rax 
cmpq %rbx, $9 
jl somelabel

Wrong!

The subq is interpreted as rax = rax - rbx, meaning that not the difference between rax and rbx is compared with 9, but the original value of rbx. Moreover, the cmpq instruction is interpreted as 9 < rbx, instead of rbx < 9

subq %rbx, %rax 
cmpq $9, %rbx 
jl somelabel

Wrong!

As in the previous option, the subq stores the difference rax - rbx in rax and in cmpq the original value of rbx is compared with 9 instead of rbx - rax.

What postfix is used for instructions using registers such as ax, di, bp?

w

Correct!

The ax, di, and bp registers store 16 bits of data (2 bytes), so we need w which stands for "word".

b

Wrong!

l

Wrong!

q

Wrong!

PreviousSyntax (Intel vs. AT&T)NextMemory

Last updated 4 months ago