Assembly language and addressing modes
הוצג
21:25
ארכיטקטורת פון נוימן
ברוב ההיסטוריה, מכונה הייתה מבצעת משימה אחת. ארגז אריג רק בד. מחשבון חיבר. כדי להניע אותה לבצע דבר חדש, בנית אותה מחדש. אז הגיעה… פשוטה במראה אך מטעה
קריינות באנגלית · כתוביות באנגלית ובסינית 中文 שאפשר להחליף ביניהן
בשיעור הזה
| English | משמעות |
|---|---|
| instruction/ɪnˈstrʌkʃn/ | A command that tells the processor what action to perform. |
| initial orders | The first instructions used to start EDSAC and translate programs from paper tape. |
| paper tape | A long strip of paper used to store information for a computer to read. |
| assembler/əˈsemblə/ | אסמבלר |
| mnemonic/nɪˈmɒnɪk/ | סימן קיצור |
| bit patterns | Arrangements of binary digits that represent instructions or data in a computer. |
| instruction set/ɪnˈstrʌkʃn set/ | סט פקודות |
| machine code/məˈʃiːn kəʊd/ | קוד מכונה |
| Assembly language/əˈsemblɪ ˈlæŋɡwɪdʒ/ | The readable form. |
| processor/ˈprəʊsesə/ | The component that executes instructions and performs the operations of a computer or similar system. |
| architecture/ˈɑːkɪtektʃə/ | The design of a computer system, including its processor and instruction set. |
| operand/ˈɒpərænd/ | אופרנד |
| high-level language/haɪ ˈlevl ˈlæŋɡwɪdʒ/ | A programming language that expresses instructions using abstractions rather than machine-specific operations. |
| statement/ˈsteɪtmənt/ | A line of code that tells a program what to do. |
| opcode/ˈɒpkəʊd/ | אוקוד (opcode) |
| symbolic address | A name used in a program to represent a memory address. |
| Pass 1 | The first reading of assembly source code to record labels and their addresses. |
| source/sɔːs/ | The original program written by a programmer before translation into machine code. |
| symbol table/ˈsɪmbl ˈteɪbl/ | טבלת סמלים |
| label/ˈleɪbl/ | תווית |
| address/əˈdres/ | An identifier specifying a location in memory or on a network. |
| Pass 2 | The second reading of assembly source code to produce machine code. |
| forward references/ˈfɔːwəd ˈrefrənsɪz/ | הפניות קדימות |
| general-purpose register | A small storage place inside a processor used to hold data during operations. |
| accumulator/əˈkjuːmjʊleɪtə/ | A register used to hold intermediate arithmetic or logical results during processing. |
| index register/ˈɪndeks ˈredʒɪstə/ | A register that holds a value added to an address during indexed addressing. |
| denary/ˈdiːnəri/ | The base-ten number system, using the digits zero through nine. |
| binary/ˈbaɪnəri/ | A number system using base two, with the digits zero and one. |
| hexadecimal/ˌheksəˈdesɪml/ | A base-sixteen number system using digits zero to nine and letters A to F. |
| Data movement | Operations that move data between registers and memory or load values into registers. |
| Input and output | Operations that receive data from outside a computer or send data out. |
| Arithmetic/əˈrɪθmətɪk/ | Calculations with numbers, such as adding and subtracting. |
| Compare/kəmˈpeə/ | An operation that checks two values and records the result in a flag. |
| Jumps | Instructions that change which instruction the processor executes next. |
| Bit manipulation | Operations that change or test individual bits within a value. |
| memory location | A place in memory that holds data and has an address. |
| loop/luːp/ | A structure that repeats a sequence of instructions. |
| addressing mode/əˈdresɪŋ məʊd/ | מצב כתובת |
| immediate addressing/ɪˈmiːdɪət əˈdresɪŋ/ | כתובת מידית |
| direct addressing/daɪˈrekt əˈdresɪŋ/ | כתובת ישירה |
| indirect addressing/ɪndaɪˈrekt əˈdresɪŋ/ | כתובת עקיפה |
| indexed addressing/ˈɪndekst əˈdresɪŋ/ | כתובת אינדקסית |
| effective address | The final memory address calculated by the processor to access an operand. |
| relative addressing/ˈrelətɪv əˈdresɪŋ/ | כתובת יחסית |
| offset/ˈɒfset/ | A value added to an address to find another memory location. |
| operand field | The part of an instruction that specifies an operand or helps locate it. |
| array/əˈreɪ/ | An indexed collection of elements arranged in one or more dimensions. |
| element/ˈelɪmənt/ | A substance made of atoms with the same proton number. |
| flag/flæɡ/ | A bit that records whether a particular condition or event has occurred. |
| conditional jump | An instruction that changes the next instruction only when a condition is met. |
| mask/mæsk/ | A pattern of bits used with logical operations to select, test, set or clear particular bits. |
שלושים-אחד הוראות בשורה של מתגים
- בשנת 1949 מחשב EDSAC בקמbridge החל לפעול מ-31 הוראות שהוגדרו על מתגים, שנכתבו על ידי David Wheeler ונקראו "ההוראות ההתחלתיות".
- משימתם הכוללת הייתה לקרוא אותות כמו A ו-S מפס נייר ולהמיר אותם למספרים שהמכונה באמת הבינה: ה-assembler הראשון.
- מאז, מתכנתים כותבים קיצורים (mnemonics) במקום דפוסי ביטים, ומערך ההוראות של המבחן עצמו הוא צאצא ישיר.
- שיעור זה עוסק בהמרה זו, בתרגול ידני של תוכנית ובחמישה האפשרויות בהן הוראה יכולה לציין את מקום הנתונים שלה.
קוד מכונה ושפת אסמבלר
- המעבד מפעיל קוד מכונה: דפוסי ביטים, ספציפיים לארכיטקטורה אחת, כאשר כל אחד מהם הוא הוראה ואופרנד.
- שפת אסמבלר היא הצורה הקריאה. כל הוראה נכתבת עם מונונימי כמו
LDD,ADDאוJMP, וכל הוראת אסמבלר הופכת להוראת קוד מכונה בדיוק אחת. - ה-אסמבלר מתרגם אותו. הקשר הוא יחס של אחד לאחד, והדבר הוא מה שמבדיל את האסמבלר משפת תכנות ברמה גבוהה, שבה הוראה אחת הופכת למספר הוראות.

כל מונונימי הופך להוראה; כל כתובת סימולית הופכת למספר

Assembly language is:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Assembly uses mnemonics and maps one-to-one to machine code; an assembler translates it.
האסמבלר דו-מעברי
- מעבר 1 קורא את המקור ובונה טבלת סימנים: בכל פעם שמופיע תווית כמו
LOOP:, כתובתה נרשמת. אין תוצרת קוד. - מעבר 2 קורא שוב את המקור ומייצר קוד, על ידי החלפת כל מונומני (mnemonic) ב-אוקוד (opcode) והחלפת כל כתובת סמלית במספר מטבלת הסימנים.
- נדרשים שני מעברים בגלל הפניות קדימות:
JMP LOOPעשוי להופיע לפני שהשורהLOOP:נראתה, ולכן הכתובת שלו אינה ידועה במעבר הראשון.

What does pass 1 of a two-pass assembler do?
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Pass 1 records where each label is (the symbol table); pass 2 then generates code, using the table to resolve label references.
Put the two-pass assembler's work in order.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
Pass 1 finds all the labels first, so pass 2 can resolve even a jump to a label defined later.
Why does the assembler need two passes?
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
A jump may target a label that appears later in the source; pass 1 finds all labels first so pass 2 can resolve them.
דוגמה פותרת: יישום השני מעברים
- התוכנית מתחילה בכתובת 100.
100 LDD COUNT
101 LOOP: DEC ACC
102 CMP #0
103 JPN LOOP
104 END
105 COUNT: 5
- מעבר 1 סופר את כתובת כל שורה ומרשם את התוויות:
LOOP= 101,COUNT= 105. דבר אחר לא נכתב. - מעבר 2 מתרגם שורה אחר שורה.
LDD COUNTהופך לאוקוד עבורLDDעם אופרנד (operand) 105;JPN LOOPהופך לאוקוד עבורJPNעם אופרנד 101. ללא מעבר 1, לא היה ניתן לתרגם את השורה הראשונה.
How a two-pass assembler works
Step through it. The assembler reads your code twice: pass 1 just finds where every label lives, so pass 2 can fill in the addresses — that is how a jump to a label defined מאוחר יותר still works.
In the worked example, pass 1 records the label LOOP with the address ____ in the symbol table.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
The program starts at 100, so the second line, LOOP: DEC ACC, occupies 101. COUNT, on the sixth line, is 105.
סט ההוראות
- סט ההוראות של קמבריד'ג כולל רגיסטר שימוש כללי אחד, האקומולטור ACC, ורגיסטר אינדקס IX. אופרנד
#nהוא עשרוני,Bnבינארי,&nהנדקסימלי, ו-<address>מספר מיקום או תווית. - העברת נתונים:
LDM #n,LDD <address>,LDI <address>,LDX <address>,LDR #n,MOV IX,STO <address>. כניסה ויציאה:IN,OUT. - חישובים:
ADD,SUB,INC,DEC. השוואה:CMP,CMI. קפיצות:JMPללא תנאי,JPEו-JPNבתנאי. עיבוד ביטים:AND,OR,XOR,LSL,LSR. לאחר מכןEND. - "ההוראות מקובעות": נקוב את הקבוצות ותן הוראה אחת מכל קבוצה.
Which of these are groups in the instruction set? Select כולם that apply.
רמת קושי 2/5 · 140 מטבעות + בונוס קטן בהשלמה הראשונה היום
Data movement, input/output, arithmetic, compare, conditional and unconditional jumps, and bit manipulation. A spreadsheet is application software, far above this level.
דוגמה פותרת: מעקב אחר תוכנית
- צייר טבלה עם עמודה עבור ה-ACC ועבור כל מיקום בזיכרון שהתוכנית משתמש בה, ואז עדכן אותה שורה בשורה עד
END.
100 LDM #0
101 STO TOTAL
102 LDD TOTAL
103 ADD #5
104 STO TOTAL
105 LDD COUNT
106 DEC ACC
107 STO COUNT
108 CMP #0
109 JPN 102
110 END
111 TOTAL: 0
112 COUNT: 3
- מעבר 1 של הלולאה: ACC 0 → 5 (TOTAL = 5), COUNT 3 → 2, השוואה אי-שוויון, קפיצה. מעבר 2: TOTAL = 10, COUNT = 1, קפיצה. מעבר 3: TOTAL = 15, COUNT = 0, השוואה שוויון, ללא קפיצה,
END. - ערכים סופיים: TOTAL = 15, COUNT = 0, ACC = 0. כתוב שורה חדשה רק כאשר ערך משתנה, ולא תפספס לעולם את ההשוואה.
In the traced program, what is the value of TOTAL when END is reached?
רמת קושי 2/5 · 140 מטבעות + בונוס קטן בהשלמה הראשונה היום
The loop adds 5 to TOTAL once for each of the three passes: 5, 10, 15.
מצבי כתובות
- מצב הכתובת מציין כיצד המעבד מזהה את הארגומנט.
| מצב | מקום הארגומנט | דוגמה |
|---|---|---|
| כתובת מיידית | הערך נמצא בתוך ההוראה עצמה | LDM #10 מטעין 10 |
| כתובת ישירה | ההוראה מכילה כתובת; השתמש בערך מאוחסן שם | LDD 200 מטעין את תוכן המקום 200 |
| כתובת עקיפה | הכתובת מכילה כתובת אחרת, שהיא מכילה את הנתונים | LDI 200 |
| כתובת אינדקסית | כתובת אפקטיבית = הכתובת הנתונה + רשמת האינדקס | LDX 200 עם IX |
| כתובת יחסית | הכתובת היא סטייה מההוראה הנוכחית | קפיצות |

אותו שדה ארגומנט, ארבע משמעויות שונות

In immediate addressing (e.g. LDM #10), the operand is:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Immediate addressing uses the literal value in the instruction (here, 10).
Match each addressing mode to its meaning.
רמת קושי 2/5 · 140 מטבעות + בונוס קטן בהשלמה הראשונה היום
Immediate = value; direct = address of the value; indirect = address of an address; indexed = base + index.
דוגמה פותרת: ארגומנט אחד, ארבע תשובות
- זיכרון: המקום 200 מכיל 300, המקום 300 מכיל 7, המקום 202 מכיל 9. רשמת האינדקס IX מכילה 2.
LDM #200מכניס 200 ל-ACC: מידי, המספר עצמו.LDD 200מכניס 300 ל-ACC: ישיר, תוכן המקום 200.LDI 200מכניס 7 ל-ACC: עקיף, תוכן הכתובת שנמצאת ב-200.LDX 200מחבר IX ל-200 וטוען את תוכן המקום 202: 9. אותו ארגומנט נכתב בארבע דרכים, ארבע ערכים שונים.

מדוע קיים כתובת אינדקסית
- מערך הוא רצף של מקומות עוקבים.
LDX 200עם IX = 0, 1, 2, … קורא אלמנטים 0, 1, 2, … ללא שינוי בהוראה. - תבנית הלולאה:
LDR #0לאפס את האינדקס,LDX ARRAYלהוצאת אלמנט, לבצע פעולה,INC IX, השוואה לאורך,JPNחזרה. - הכיפוי הישיר דורש הוראה נפרדת לכל אלמנט; הכיפוי הממוספר דורש הוראה אחת.

Indexed addressing is most useful for:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
The effective address is base address + index register, so increasing the index walks through an array.
השוואה וקפיצה
CMP #nאוCMP <address>משווים את ACC לערך ומגדירים את הדגל. הם לא משנים את ה-ACC.JPE <address>מקפיץ אם ההשוואה האחרונה מצאה ששני הערכים שווים;JPN <address>מקפיץ אם הם לא היו שווים;JMP <address>תמיד מקפיץ.- פקודת
IFבשפת גבוהה הופכת לפקודתCMPשאחריה קפיצה מותנית; לולאה הופכת להשוואה וקפיצה חזרה לתווית.

CMP #0 changes the value held in the accumulator.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
A compare only sets the flag that the next conditional jump reads. The ACC is unchanged, which is why the trace shows no new ACC value on a CMP line.
סימונים נופלים מהיד
LDM #10מטעין את המספר 10;LDD 10מטעין את תוכן המקום 10. ה-#הוא ההבדל כולו.#הוא עשרוני,Bהוא בינארי,&הוא אקסא-decimal. ה-AND &0Fוה-AND B00001111הם אותו מסכה; ה-AND #15גם כן.CMPמשאיר את ה-ACC ללא שינוי; הוא רק מגדיר את הדגל.JPNמקפיץ כאשר הערכים אינם שווים.- מעבר 1 של המאסמבלר (assembler) כותב אין קוד. הפלט שלו היא טבלת הסימנים, וההפניות הקדמיות הן הסיבה לקיומה.
הבנתך מושלמת
- קוד מכונה הוא תבניות ביט; אסמבלי הוא מונחים קיצורים, אחד לאחד, המתורגם על ידי מתרגם
- שני מעברים: מעבר 1 בונה את טבלת הסימנים של כתובות התוויות, מעבר 2 מייצר קוד; נדרש עבור הפניות קדמיות.
- מעקב עם טבלת ACC וכל מקום, שורה לכל שינוי; CMP מגדיר את הדגל, JPE/JPN קוראים אותו
- הכיפוי: מיידית
#nהערך · ישיר תוכן הכתובת · עקיף כתובת של הכתובת · ממוספר כתובת + IX (מערכות) · יחסי סטייה
מה השתבש? רק צוות האתר רואה זאת.