לדלג לתוכן

1.2 - שלום עולם - פתרון

תרגול 1 – הבנת רגיסטרים

תשובות תיאורטיות (אין צורך בקוד).

  1. AX – לחשבון, BX – כתובות, CX – מונה, DX – כללי ו־I/O

  2. AX בגודל 16 ביט. AH = 8 הביטים העליונים, AL = 8 הביטים התחתונים

  3. AH = 0x5A, AL = 0x3C


תרגול 2 – שימוש ב־MOV ו־LEA

IDEAL
MODEL small
STACK 100h

DATASEG
myVal dw ?

CODESEG
start:
    mov ax, @data
    mov ds, ax

    ; Exercise 1
    mov bx, 1000
    mov dx, bx

    ; Exercise 2
    mov myVal, 5

    ; Exercise 3
    mov bx, 20
    lea si, [bx+10]

exit:
    mov ax, 4c00h
    int 21h
END start

תרגול 3 – פעולות חשבוניות

    ; Exercise 1
    mov ax, 20
    add ax, 15

    ; Exercise 2
    sub ax, bx

    ; Exercise 3
    mov cx, 0
    inc cx
    inc cx
    inc cx

    ; Exercise 4
    dec cx
    dec cx
    dec cx

תרגול 4 – כפל וחילוק

    ; Exercise 1 - 8-bit multiplication
    mov al, 10
    mov bl, 3
    mul bl ; AX = AL * BL

    ; Exercise 2 - 16-bit multiplication
    mov ax, 30
    mov bx, 4
    mul bx ; DX:AX = AX * BX

    ; Exercise 3 - 8-bit division
    mov ax, 1234h
    mov bl, 10h
    div bl ; AL = AX / BL ; AH = remainder

    ; Exercise 4 - 16-bit division
    mov dx, 0
    mov ax, 1234h
    mov cx, 10
    div cx ; AX = DX:AX / CX ; DX = remainder

תרגול 5 – פעולות לוגיות

    ; Exercise 1 - AND
    mov al, 11110000b
    and al, 00001111b

    ; Exercise 2 - OR
    mov al, 00000000b
    or al, 00000011b ; turns on the last two bits

    ; Exercise 3 - XOR
    mov al, 11111111b
    xor al, 11001100b

    ; Exercise 4 - zero out a register
    xor ax, ax

    ; Exercise 5 - NOT
    mov bl, 11001100b
    not bl

תרגול 6 – קריאה וכתיבה לזיכרון

DATASEG
var1 db ?
var2 db ?
var3 dw ?

CODESEG
start:
    mov ax, @data
    mov ds, ax

    ; Exercise 1 - writing
    mov var1, 9

    ; Exercise 2 - reading
    mov al, var2

    ; Exercise 3 - writing BX
    mov bx, 0x1234
    mov var3, bx

תרגול 7 – תרגול מסכם

DATASEG
result dw ?
input1 db 11001100b
input2 db 10101010b
output db ?

CODESEG
start:
    mov ax, @data
    mov ds, ax

    ; Exercise 1
    xor ax, ax
    add ax, 100
    add ax, ax
    mov result, ax

    ; Exercise 2
    mov al, input1
    and al, input2
    mov output, al

    ; Exercise 3
    mov al, input1
    not al
    mov output, al