8086 Assembler Tutorial for Beginners (Part
7)
Program Flow Control |
הדרכה בתכנות אסמבלר 8086 למתחילים (חלק
7)
בקרת זרימת התוכנית |
Controlling the program flow is a very important thing, this is where your program can make decisions according to certain conditions. | שליטה בזרימת התוכנית היא דבר חשוב מאוד, זה המקום בו התוכנית שלך יכולה לבצע החלטות לפי תנאים מסוימים. |
Unconditional Jumps The basic instruction that transfers control to another point in the program is JMP. The basic syntax of JMP instruction:
To declare a label in your program, just type its name and add ":" to the end, label can be any character combination but it cannot start with a number, for example here are 3 legal label definitions:
Label can be declared on a separate line or before any other instruction, for example:
Here is an example of JMP instruction: |
פקודות דילוג ללא תנאי להגדרת תווית בתוכנית שלך,
פשוט כותבים את שם התווית ובסיומה מוסיפים ":". התווית
יכולה להיות כל שילוב של אותיות או סימנים אבל לא יכולה להתחיל עם מספר.
label1: ניתן להגדיר תווית בשורה נפרדת או לפני כל פקודה, למשל:
להלן דוגמה של פקודת JMP: |
ORG 100h |
|
|
Instruction |
Description תיאור |
Condition |
Opposite Instruction |
JZ , JE |
Jump if Zero (Equal) . (דלג אם אפס (שווה |
ZF = 1 | JNZ, JNE |
Jump if Carry (Below, Not Above Equal). |
CF = 1 | JNC, JNB, JAE | |
JS |
Jump if Sign . דלג אם הסימן שלילי |
SF = 1 | JNS |
JO |
Jump if Overflow . דלג אם יש גלישת יתר |
OF = 1 | JNO |
JPE, JP |
Jump if Parity Even . |
PF = 1 | JPO |
JNZ , JNE |
Jump if Not Zero (Not Equal). |
ZF = 0 | JZ, JE |
Jump if Not Carry (Not Below, Above Equal). |
CF = 0 | JC, JB, JNAE | |
JNS | Jump if Not Sign . דלג אם הסימן חיובי | SF = 0 | JS |
JNO |
Jump if Not Overflow . דלג אם אין גלישת יתר |
OF = 0 | JO |
JPO, JNP |
Jump if Parity Odd (No Parity) . |
PF = 0 | JPE, JP |
Copyright 2002-2003 - Emu8086, Inc. All rights reserved. - Portions Copyright 1997-2003 Barry Allyn. All rights reserved.
Hebrew Version Copyright COVAL Computer Software - Copyright © 2003 R&D Private Advisers All rights reserved.
As you can see there are some instructions that do that same thing, that's correct,
they even are assembled into the same machine code, so it's good to remember that
when you compile JE instruction - you will get it disassembled as: JZ. Different names are used to make programs easier to understand and code. Jump instructions for signed numbers: |
כפי שאתה יכול לראות ישנן כמה פקודות שעושות
אותו דבר, זה נכון, הן אפילו מרוכזות עם אותו צופן מכונה, לכן זה טוב
לזכור שכאשר אתה מבצע הידור (קומפילציה) של הפקודה
JE - אתה תקבל ב-Debugger
כמו JZ. |
Instruction |
Description תיאור |
Condition |
Opposite Instruction |
JE , JZ |
Jump if Equal (=)
דלג אם
שווה. |
ZF = 1 | JNE, JNZ |
JNE , JNZ |
Jump if Not Equal (<>)
דלג אם לא שווה. Jump if Not Zero - דלג אם שונה מאפס. |
ZF = 0 | JE, JZ |
JG , JNLE |
Jump if Greater (>)
דלג אם גדול. |
ZF = 0 and SF = OF |
JNG, JLE |
JL , JNGE |
Jump if Less (<)
דלג אם קטן. |
SF <> OF | JNL, JGE |
JGE , JNL |
|
SF = OF | JNGE, JL |
JLE , JNG |
|
ZF = 1 or SF <> OF |
JNLE, JG |
<> - sign means not equal.
Jump instructions for unsigned numbers |
הערה: סימן <> - פירושו לא שווה (שונה). פקודות קפיצה למספרים לא מסומנים: |
Copyright 2002-2003 - Emu8086, Inc. All rights reserved. - Portions Copyright 1997-2003 Barry Allyn. All rights reserved.
Hebrew Version Copyright COVAL Computer Software - Copyright © 2003 R&D Private Advisers All rights reserved.
Instruction |
Description תיאור |
Condition |
Opposite Instruction |
JE , JZ |
Jump if Equal (=)
דלג אם
שווה. Jump if Zero (0) דלג אם אפס. |
ZF = 1 | JNE, JNZ |
JNE , JNZ |
Jump if Not Equal (<>)
דלג אם לא שווה. Jump if Not Zero - דלג אם שונה מאפס. |
ZF = 0 | JE, JZ |
JA , JNBE |
Jump if Above (>)
דלג אם מעל. |
CF = 0 and ZF = 0 |
JNA, JBE |
Jump if Below (<)
דלג אם מתחת |
CF = 1 | JNB, JAE, JNC | |
Jump if Above or Equal (>=)
|
CF = 0 | JNAE, JB | |
Jump if Below or Equal (<=)
|
CF = 1 or ZF = 1 |
JNBE, JA |
Generally, when it is required to compare numeric values CMP instruction
is used (it does the same as SUB (subtract) instruction, but does not keep
the result, just affects the flags). The logic is very simple, for example: it's required to compare 5 and 2, 5 - 2 = 3 the result is not zero (Zero Flag is set to 0). Another example: it's required to compare 7 and 7, 7 - 7 = 0 the result is zero! (Zero Flag is set to 1 and JZ or JE will do the jump). Here is an example of CMP instruction and conditional jump: |
בדרך כלל, כאשר נדרש להשוות ערכים מספריים
משתמשים בפקודת CMP
, אשר מבצעת את אותה פעולה כמו פקודת החיסור SUB,
אך לא שומרת את התוצאה, אלא משפיעה על מצב הדגלים. |
include emu8086.inc |
Try the above example with different numbers for AL and BL, open flags by clicking on [FLAGS] button, use [Single Step] and see what happens, don't forget to recompile and reload after every change (use F5 shortcut). |
נסה את הדוגמה הקודמת עם ערכים שונים עבור
AL ו- BL, פתח
את חלון הדגלים על ידי הכפתור שבתחתית האמולטור, השתמש בצעד יחיד
וראה מה מתרחש. |
All conditional jumps have one big limitation, unlike JMP instruction
they can only jump 127 bytes forward and 128 bytes backward (note that most
instructions are assembled into 3 or more bytes).
label_x: - can be any valid label name.
|
לכל הקפיצות המותנות הגבלה גדולה. פרט מפקודת
JMP הם יכולות לדלג רק 127 צעדים
קדימה ו- 128 צעדים (בתים) אחורה. ראה שלרוב פקודות הקפיצה
(דילוג) 3 או יותר בתים של זיכרון התוכנית.
תווית :label_x יכולה להיות כל שם תקין. דוגמה בהמשך: |
include emu8086.inc |
Another, yet rarely used method is providing an immediate value instead of a label. When immediate value starts with a '$' character relative jump is performed, otherwise compiler calculates instruction that jumps directly to given offset. For example: |
שיטה נוספת, בשימוש נדיר, זה לספק ערך מיידי במקום תווית.
|
ORG 100h |
Copyright 2002-2003 - Emu8086, Inc. All rights reserved. - Portions Copyright 1997-2003 Barry Allyn. All rights reserved.
Hebrew Version Copyright COVAL Computer Software - Copyright © 2003 R&D Private Advisers All rights reserved.