8086 Assembler Tutorial for Beginners (Part 4)

Interrupts

הדרכה בתכנות אסמבלר 8086 למתחילים (חלק 4)  

פסיקות

Interrupts can be seen as a number of functions. These functions make the programming much easier, instead of writing a code to print a character you can simply call the interrupt and it will do everything for you. There are also interrupt functions that work with disk drive and other hardware. We call such functions software interrupts.

Interrupts are also triggered by different hardware, these are called hardware interrupts. Currently we are interested in software interrupts only.


To make a software interrupt there is an INT instruction, it has very simple syntax:

INT value

Where value can be a number between 0 to 255 (or 0 to 0FFh),generally we will use hexadecimal numbers.
You may think that there are only 256 functions, but that is not correct. Each interrupt may have sub-functions.
To specify a sub-function AH register should be set before calling interrupt.
Each interrupt may have up to 256 sub-functions (so we get 256 * 256 = 65536 functions). In general AH register is used, but sometimes other registers maybe in use. Generally other registers are used to pass parameters and data to sub-function.

The following example uses INT 10h sub-function 0Eh to type a "Hello!" message. This functions displays a character on the screen, advancing the cursor and scrolling the screen as necessary.

ניתן להתייחס לפסיקות כמספר פונקציות. הפונקציות מקלות על עבודת המתכנת, במקום לכתוב קוד להדפסת אות אתה יכול פשוט לקרוא לפסיקה והיא תעשה הכול בשבילך. קיימות גם פונקציות העובדות עם כונני דיסקים וחומרה אחרת. אנו קוראים לפונקציות האלה פסיקות דרך תוכנה.


ניתן להפעיל פסיקות גם על ידי ציוד (חומרה), פסיקות אלו נקראות פסיקות דרך חומרה.   לפי שעה אנחנו מעוניינים בפסיקות דרך תוכנה בלבד.


להפעלת פסיקה דרך תוכנה נשתמש בפקודה INT, יש לה תחביר פשוט מאוד:

ערך  INT

הערך יכול להיות  מספר בין 0 ל- 255 (או 0 ל- 0FFh), בדרך כלל נשתמש במספרים של בסיס 16.
אתה יכול לחשוב שיש רק 256 פסיקות, אבל זה לא נכון. לכל פסיקה יכולה להיות תת שיגרה.
לצורך הפעלת תת שיגרה יש לקבוע את מספרה באוגר AH לפני הפעלת הפסיקה.
כל פסיקה יכולה לכלול עד 256 תת שגרות (לכן נקבל 65536 = 256* 256 פונקציות אפשריות) . בדרך כלל משתמשים באוגר AH , אבל לפעמים ניתן להשתמש באוגרים אחרים.  בדרך כלל אוגרים אחרים משמשים להעברת פרמטרים ונתונים לשגרות.


הדוגמה הבאה משמשת בפסיקה INT 10h להדפסת הודעת "שלום!" במסך.
הפסיקה הזאת מציגה אות על המסך, מקדימה את הסמן וגורמת לגלילת המסך על פי הצורך.

 #MAKE_COM#        ; instruct compiler to make COM file.
 ORG    100h       ;               .הגדרות לבניית קובץ רגיל

                   ; The sub-function that we are using
                   ; does not modify the AH register on
                   ; return, so we may set it only once.

                   ;    כאשר התת שיגרה חוזרת לתוכנית הראשית
                   ;           ,AH היא לא משנה את תוכן אוגר
                   ;  .בגלל זה מגדירים אותו רק פעם אחד בלבד
                   ;                 

 MOV    AH, 0Eh    ; select sub-function -        בחר שיגרה

; INT 10h / 0Eh sub-function - 0Eh פסיקה מספר 10 עם פונקציה
; receives an ASCII code of the -         מקבל צופן אסקי של
; character that will be printed -        האות שצריך להדפיס
; in AL register.                                  AL באוגר

 MOV    AL, 'H'    ; ASCII code: 72  : צופן אסקי
 INT    10h        ; print it!        !הדפס אותו

 MOV    AL, 'e'    ; ASCII code: 101  : צופן אסקי
 INT    10h        ; print it!         !הדפס אותו

 MOV    AL, 'l'    ; ASCII code: 108  : צופן אסקי
 INT    10h        ; print it!         !הדפס אותו

 MOV    AL, 'l'    ; ASCII code: 108  : צופן אסקי
 INT    10h        ; print it!         !הדפס אותו

 MOV    AL, 'o'    ; ASCII code: 111  : צופן אסקי
 INT    10h        ; print it!         !הדפס אותו

 MOV    AL, '!'    ; ASCII code: 33  : צופן אסקי
 INT    10h        ; print it        !הדפס אותו!

 RET               ; returns to operating system.
                   ; חזרה למערכת הפעלה או לתוכנית הראשי
Copy & paste the above program to Emu8086 source code editor, and press [Compile and Emulate] button. Run it!

See list of supported interrupts for more information about interrupts.
 
העתק והדבק את התוכנית שלמעלה לתוך עורך התוכניות של EMU8086 , לחץ על כפתור [עריכה והדמיה].  הרץ!

ליותר מידע על פסיקות ראה רשימה של פסיקות הנתמכות.

<<< to Part 3 <<   >> to Part 5 >>>

<<< לחלק 5 <<   >> לחלק 3 >>>