לדלג לתוכן

1.6 פסיקות פתרון תרגילי העשרה

תרגיל 6 – תצוגת שעה מה־BIOS

IDEAL
MODEL small
STACK 100h
DATASEG
msg db 'Seconds since midnight: $'
newline db 13, 10, '$'
CODESEG
start:
    ; קבלת מספר הטיקים מאז חצות
    mov ah, 00h
    int 1Ah     ; CX:DX = Tick count

    ; נעבוד רק עם DX (החלק הנמוך)
    mov ax, dx
    mov bx, 55
    div bx      ; AX = seconds

    ; הדפסה
    mov dx, offset msg
    mov ah, 09h
    int 21h

    call print_number

    mov ax, 4C00h
    int 21h

; פונקציה להדפסת AX כ-Decimal
print_number:
    push ax
    mov cx, 0
.next:
    xor dx, dx
    mov bx, 10
    div bx
    push dx
    inc cx
    test ax, ax
    jnz .next

.print:
    pop dx
    add dl, '0'
    mov ah, 02h
    int 21h
    loop .print

    pop ax
    ret
END start

תרגיל 7 – Press any key to continue…

IDEAL
MODEL small
STACK 100h
DATASEG
msg db 'Press any key to continue...', 13, 10, '$'
CODESEG
start:
    mov dx, offset msg
    mov ah, 09h
    int 21h

    ; פסיקה 16h – קריאה למקלדת ללא הדפסה
    mov ah, 00h
    int 16h

    mov ax, 4C00h
    int 21h
END start

תרגיל 8 – טיפול בשגיאה בפתיחת קובץ

IDEAL
MODEL small
STACK 100h
DATASEG
filename db 'nofile.txt', 0
msg_ok db 'Opened!', 13, 10, '$'
msg_err db 'Error!', 13, 10, '$'
CODESEG
start:
    mov ah, 3Dh
    mov al, 0        ; מצב קריאה
    mov dx, offset filename
    int 21h

    jc error         ; אם הייתה שגיאה, CF = 1

    ; הצלחה
    mov dx, offset msg_ok
    mov ah, 09h
    int 21h
    jmp exit

error:
    mov dx, offset msg_err
    mov ah, 09h
    int 21h

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