1.8 אקסטה פתרון
תרגול – קפיצות, הזזות, והחלפות במעבד 8086
תרגיל 1 – קפיצה Far¶
IDEAL
MODEL small
STACK 100h
DATASEG
msg db 'Hello from FAR$', 0
CODESEG
start:
call far ptr printMessage
mov ax, 4C00h
int 21h
CSEG2 segment
assume cs:CSEG2
printMessage proc far
mov ah, 09h
mov dx, offset msg
int 21h
ret
printMessage endp
CSEG2 ends
END start
תרגיל 2 – שימוש ב־SHL ו־SHR¶
IDEAL
MODEL small
STACK 100h
DATASEG
CODESEG
start:
mov al, 3
shl al, 1
call print_al
shr al, 1
call print_al
mov ax, 4C00h
int 21h
print_al:
push ax
mov ah, 0Eh
add al, '0'
int 10h
pop ax
ret
END start
תרגיל 3 – שימוש ב־XCHG¶
IDEAL
MODEL small
STACK 100h
DATASEG
newline db 13, 10, '$'
CODESEG
start:
mov ax, 5
mov bx, 9
xchg ax, bx
; הדפסת AX
mov al, ah
call print_hex
mov al, al
call print_hex
call newline_print
; הדפסת BX
mov ax, bx
mov al, ah
call print_hex
mov al, al
call print_hex
mov ax, 4C00h
int 21h
print_hex:
push ax
mov ah, 0Eh
and al, 0Fh
add al, '0'
cmp al, '9'
jbe skip
add al, 7
skip:
int 10h
pop ax
ret
newline_print:
mov ah, 09h
mov dx, offset newline
int 21h
ret
END start
תרגיל 4 – שימוש ב־LOOP¶
IDEAL
MODEL small
STACK 100h
DATASEG
CODESEG
start:
mov cx, 5
print_loop:
mov ah, 0Eh
mov al, 'X'
int 10h
loop print_loop
mov ax, 4C00h
int 21h
END start
תרגיל בונוס – לולאה שמכפילה מספר כל פעם ב־2¶
IDEAL
MODEL small
STACK 100h
DATASEG
newline db 13, 10, '$'
CODESEG
start:
mov al, 1
mov cx, 4
power_loop:
shl al, 1
call print_al
call newline_print
loop power_loop
mov ax, 4C00h
int 21h
print_al:
push ax
mov ah, 0Eh
mov bl, al
call print_decimal
pop ax
ret
print_decimal:
xor cx, cx
.next:
xor dx, dx
mov ax, bx
mov bx, 10
div bx
push dx
inc cx
mov bx, ax
test ax, ax
jnz .next
.print:
pop dx
add dl, '0'
mov ah, 02h
mov dl, dl
int 21h
loop .print
ret
newline_print:
mov ah, 09h
mov dx, offset newline
int 21h
ret
END start