Corrected Version — Chapter 2-2 Assembly Language Basics (Notes & Code)
Corrections Applied:
• Fixed DIV example remainder printing.
• Fixed Base+Index+Displacement example (EAX must be initialized before MUL).
• Added size■matching rule for MOV var.
• Added clarifications where needed.
-----------------------------
1) Directives vs Instructions
(unchanged content)
2) Data Types
(unchanged content)
3) Addressing Modes
(unchanged content)
4) OFFSET vs [] Clarification
MOV dest, var is valid only if the size of dest matches the variable.
Otherwise you must use:
movzx eax, BYTE PTR var
movzx eax, WORD PTR var
Or sign■extend equivalents.
5) Arithmetic — MUL / IMUL / DIV
IMPORTANT correction:
In 32■bit DIV:
xor edx, edx ; always clear before div
mov eax, num1
mov ebx, num2
div ebx ; quotient=EAX, remainder=EDX
Correct remainder printing:
mov ecx, edx ; save remainder
mov eax, ecx
call WriteDec
(Old incorrect line “mov eax, edx after msg load” removed.)
6) Base + Index + Displacement Example (Corrected)
Record size = 12 bytes, so index * 12 must be computed using EAX:
mov ebx, OFFSET myList
mov eax, 1 ; record index
mov ecx, 12
mul ecx ; EAX = index * 12
mov esi, eax
mov eax, [ebx + esi + 4] ; field B offset = 4
7) LEA Notes
(unchanged but clarified)
LEA does not dereference memory. It only computes effective addresses.
8) Matrix Example Clarification
This version is correct ONLY because matrix is BYTE elements (TYPE=1).
If WORD/DWORD arrays are used, multiply index by TYPE.
Other sections unchanged because they were correct.
-----------------------------
Full corrected content ready for study.