Assembly Language Programming Lesson 1
Assembly Language Programming Lesson 1
LANGUAGE
PROGRAMMING
WHAT IS ASSEMBLY LANGUAGE?
• Why do you think assembly language uses mnemonics like MOV and
ADD instead of binary numbers, and how does this make programming
easier or harder?
ANSWER
• Assembly language uses words like MOV and ADD to make it easier for
people to understand what the computer is doing. These are called
mnemonics. Instead of writing long strings of 1s and 0s (binary), we can
use simple words to give the computer instructions.
• This makes programming a bit easier than using just machine code. But
it's still more challenging than using modern languages like Python
because you need to understand how the computer works inside.
• An assembler is a tool that changes these simple words into binary so
the computer can understand and run the program.
BASIC COMPONENTS OF ASSEMBLY
LANGUAGE
• This are the building blocks that allow you to communicate directly with the computer hardware.
• All of these parts work together like steps in a recipe to help the computer do something:
• Instructions are like the actions (e.g., add, move, jump) they tell the computer what to do.
• Operands are the ingredients they are the data the instruction uses, like numbers or
memory locations.
• Mnemonics are the words we use (like MOV, ADD, JMP) that are easier to read than binary.
• Registers are like tiny storage spaces inside the CPU where the data is kept while the
computer works on it.
• So for example, if you write ADD A, B, it tells the computer to add what's in register A and
register B and store the result. Each part plays a key role in making the program run
correct
ASSEMBLY LANGUAGE
• Processor-specific
• An assembly language program is unique to a particular processor.
• It may not be compatible with other processors.
For example, Each type of CPU speaks its own ‘version’ of assembly
language. So, the code you write for one processor, like the Intel x86,
won’t work on a different one, like an ARM processor.
DO NOW!
1. b) ADD
2. The role of an assembler is to execute instructions.
False , The assembler translates assembly code into machine code.
3. Define the term mnemonic in the context of assembly language.
A mnemonic is a human-readable instruction used in assembly language that represents a
machine code operation.
4. Why is assembly language described as low-level? Because it is closely related to machine
code and it is machine friendly
5. What does the instruction ADD A, B mean? It tells the CPU to add the values in register A
and register B, and usually store the result in A.
CPU REGISTERS
• General purpose registers- hold data for various operations ,meaning they are
flexible
What they do: Hold data temporarily during operations (like in arithmetic or logic
instructions).
Example Storing values to be added: MOV AX,
Example in Assembly Language:
MOV AX, 5
MOV BX, 10
ADD AX, BX
Here, AX and BX are general-purpose registers holding values to be added
CPU REGISTERS
- Flags are indicators that tell the CPU about the result of an operation
1. Zero Flag(ZF) It is set when the results of an operation is zero
“Was the result zero?” If yes, the CPU might jump to a different instruction.
Example: 5 - 5 sets ZF because the result is 0.
The CPU might use this flag to decide whether to jump to a different instruction (e.g., if result
is zero, end the loop).
2. Carry Flag(CF) It is set if an arithmetic operation produces a result too large for the
register to hold.
“Did the result not fit in the register?” Used in addition (like when adding big numbers).
Example: Adding 255 + 1 (if max is 255) causes a carry
FLAGS IN ASSEMBLY
• Why do you think the CPU uses flags like Zero, Carry, Overflow, and
Sign when running a program, and how might they help the computer
make decisions?"
ANSWER
• These flags allow the CPU to make decisions during the execution of a
program. For example, after an operation, the CPU may use the Zero
flag to check if two values are equal and branch accordingly, or use the
Carry flag to chain multi-byte arithmetic operations. The Overflow and
Sign flags help manage signed numbers and error conditions in a way
that ensures the program runs as expected.
HOMEWORK
✅ Step-by-Step Explanation:
MOV A, 5→ Store the value 5 in register A.
MOV B, 3→ Store the value 3 in register B.
JMP skip→ This is a jump instruction. It tells the CPU to skip the next line(s) and go directly to the label skip. So,
the next line (ADD A, B) is not executed.
ADD A, B (skipped)→ Normally, this would add the value of B (3) to A (5), resulting in A = 8.But this line is skipped
because of the jump.skip:
MOV C, A→ Move the value in A (which is still 5) into C.
So, now C = 5
Final Result:s A = 5 B = 3 C = 5
The program moves numbers into registers A and B, jumps over the addition, and finally stores the original value
of A into C.