1.6 - פסיקות - פתרון
תרגיל 1 – print_A.asm
IDEAL
MODEL small
STACK 100h
CODESEG
start:
mov ah, 02h ; DOS - single character
mov dl, 'A'
int 21h
mov ax, 4C00h ; standard exit
int 21h
END start
תרגיל 2 – echo_char.asm
IDEAL
MODEL small
STACK 100h
CODESEG
start:
mov ah, 01h ; DOS: character input
int 21h ; AL ← the character
mov ah, 0Eh ; BIOS TTY output
mov bh, 0
mov bl, 7
int 10h ; displays AL
mov ax, 4C00h
int 21h
END start
תרגיל 3 – print_string.asm
IDEAL
MODEL small
STACK 100h
DATASEG
msg db 'Hello, DOS!$',0
CODESEG
start:
mov ax, @data
mov ds, ax
mov dx, offset msg
mov ah, 09h
int 21h ; print
mov ax, 4C00h
int 21h
END start
תרגיל 4 – read_and_print.asm
IDEAL
MODEL small
STACK 100h
DATASEG
buffer db 19 ; max length (up to 19)
db 0 ; DOS will write the actual length here
db 19 dup (0) ; space for the letters
dollar db '$',0 ; used as terminator
CODESEG
start:
mov ax, @data
mov ds, ax
; --- read ---
mov dx, offset buffer
mov ah, 0Ah
int 21h
; --- add '$' at the end ---
mov bl, [buffer+1] ; length that was typed
mov bh, 0
mov si, offset buffer
add si, 2
add si, bx ; SI points after the characters
mov byte ptr [si], '$'
; --- print ---
mov dx, offset buffer+2
mov ah, 09h
int 21h
mov ax, 4C00h
int 21h
END start
תרגיל 5 – custom_int60.asm
IDEAL
MODEL small
STACK 100h
DATASEG
old_off dw ?
old_seg dw ?
CODESEG
start:
cli ; safety
; --- saving the old Vector ---
mov ax, 0
mov es, ax ; ES=0000h -> IVT
mov bx, 60h
shl bx, 2 ; BX = 60h*4 = 0180h
mov ax, word ptr es:[bx]
mov old_off, ax
mov ax, word ptr es:[bx+2]
mov old_seg, ax
; --- installing a new Handler ---
mov ax, seg myHandler
mov word ptr es:[bx+2], ax
mov ax, offset myHandler
mov word ptr es:[bx], ax
sti
; --- calling INT 60h twice ---
int 60h
int 60h
; --- restoring the old Vector ---
cli
mov ax, old_seg
mov word ptr es:[bx+2], ax
mov ax, old_off
mov word ptr es:[bx], ax
sti
; exit
mov ax, 4C00h
int 21h
; ----- Handler: prints '*' -----
myHandler:
push ax
mov ah, 0Eh
mov al, '*'
mov bh, 0
mov bl, 7
int 10h
pop ax
iret
END start