Computer Architecture and Assembly Language

Slides:



Advertisements
Similar presentations
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Advertisements

Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
Practical session 7 review. Little – Endian What’s in memory? Section.rodata a: DB ‘hello’, 0x20, ’world’, 10, 0 b: DW ‘hello’, 0x20, ’world’, 10, 0 c:
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
תרגול 5 רקורסיות. רקורסיה קריאה של פונקציה לעצמה –באופן ישיר או באופן עקיף היתרון : תכנות של דברים מסובכים נעשה ברור ונוח יותר, מכיוון שזו למעשה צורת.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
NASM Preprocessor. NASM preprocessor  NASM contains a powerful macro processor, which supports conditional assembly, multi-level file inclusion, two.
Accessing parameters from the stack and calling functions.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Position Independent Code self sufficiency of combining program.
Practical session 8 Assignment 3. Game of life A zero-player game. Simulates Evolution, of an infinite two-dimensional matrix’s cells. Each cell can be.
Practical Session 8 Computer Architecture and Assembly Language.
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Practical Session 6. NASM Preprocessor NASM contains a powerful macro processor, which supports conditional assembly multi-level file inclusion two forms.
Practical Session 4 Computer Architecture and Assembly Language.
Functions/Methods in Assembly
Assembly 07. Outline Boxes within Boxes Procedure Definition call, ret Saving / Restoring Registers Argument(s) Return Value(s) Global vs. Local Data.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Practical Session 6 Computer Architecture and Assembly Language.
Practical Session 9 Computer Architecture and Assembly Language.
Procedures Dr. Hadi Al Saadi Large problems can be divided into smaller tasks to make them more manageable A procedure is the ASM equivalent of a Java.
Lecture 15 Advanced Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Practical Session 3.
Practical Session 5.
Stack Operations Dr. Hadi AL Saadi.
מספרים אקראיים ניתן לייצר מספרים אקראיים ע"י הפונקציה int rand(void);
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
Microprocessor and Assembly Language
Introduction to Compilers Tim Teitelbaum
Assembly Language Programming Part 2
High-Level Language Interface
(The Stack and Procedures)
Practical Session 7.
Computer Architecture and Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
Practical Session 8, Memory Management 2
Programming 8086 – Part IV Stacks, Macros
Computer Architecture and Assembly Language
Fundamentals of Computer Organisation & Architecture
Practical Session 9.
Computer Architecture and Assembly Language
Practical Session 9, Memory Management continues
Practical Session 4.
(The Stack and Procedures)
Computer Architecture and Assembly Language
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Multi-modules programming
Computer Architecture and Assembly Language
X86 Assembly Review.
Some Assembly (Part 2) set.html.
Computer Architecture and Assembly Language
(The Stack and Procedures)
Computer Organization and Assembly Language
ICS51 Introductory Computer Organization
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Practical Session 8, Memory Management 2
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

Computer Architecture and Assembly Language Practical Session 9

Game of life Simulates Evolution of two-dimensional matrix’s cells. Each cell can be alive or dead. A cell’s state in each iteration (generation) is set with accordance to its state and its neighbors’ states.

Input file Each cell is given an initial state from input file. 1 alive cells are denoted by ‘1’ in input file empty (dead) cells are denoted by space in input file At each generation, a cell will determine its next state according to its former state and its neighbors’ former states, using the game rules. After calculation of the next state, each cell updates its state. 1 1 2 1 calculate next state update next state

Cell neighbors Every cell has 8 neighbors Even at the board edges me cells of the first row are neighbors of the cells in the last row cells of the first column are neighbors of the cells in the last column

Game rules If the cell is currently alive, then it will remain alive in the next generation if and only if exactly 2 or 3 of its neighbors are currently alive. Otherwise it dies. Examples: N3 N2 N1 N5 me N4 N8 N7 N6 N3 N2 N1 N5 me N4 N8 N7 N6 me dies me stays alive N3 N2 N1 N5 me N4 N8 N7 N6 A dead cell remains dead in the next generation, unless it has exactly 3 living neighbors. Examples: N3 N2 N1 N5 me N4 N8 N7 N6 N3 N2 N1 N5 me N4 N8 N7 N6 me comes alive me stays dead Organism age is the number of generation it was alive in a row. Maximum age is 9*. *A cell does not die after age 9, it continues its life according to the game rules, but its age stays unchanged.

n cell instances (2-dimensional matrix) a printer a scheduler Implementation Using the co-routine mechanism, with the following co-routines: n cell instances (2-dimensional matrix) a printer a scheduler

(stage 1) resume  (stage 2) resume A Cell Cell can be alive(‘1’-’9’) or dead(‘ ‘) Cell executes a simple infinite loop: Calculate next state using current state (of a cell and its neighbors) Update current state of to a new state After each of these two stages, the cell co-routine must resume the scheduler. In other words, it loops (forever) over: (stage 1) resume  (stage 2) resume

A scheduler The printer implements simple round-robin algorithm void scheduler (int cycles) iterate cycles times over all cells after each K resumes of cell co-routines, resume the printer (1) resume  (2) resume … right before exit the program, resume the printer once more, and then terminate the process What is the definition of K?? The printer Prints the entire “world” (the global array), whenever it gets “time”.

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) print matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow > ass3 <filename> <length> <width> <t> <K> <filename> - name of a file contain the initial state of the game board. A series of size <width> of ‘ ‘ and ‘1’ in each line. The file contain <length> lines. <t> - number of generations <K> - printing frequency your array dimensions will be <width>*<length>

Program’s flow When invoked, and using the co-routines mechanism from class, your application will: Set up: a state array, Length, Width, K, t Initiate all co-routines: each cell gets parameters i,j - its indices in the global array a scheduler gets t, K, Length, and Width as parameters a printer gets Length and Width as parameters Initiate an array CORS of pointers to: cell0,0,…,celllength-1,width-1, scheduler, printer  Transfer control to scheduler

Program’s flow Each cell in CORS array will point directly to the top of the stack of the corresponded co-routine. You don’t have to implement the co-routine structure as presented in the practical session. CORS: CO(0,0) CO(0,1) … CO(n-1, n-1) CoPrinter CoScheduler CO(i,j): Function Flags SP(i,j) CORS: SP(0,0) SP(0,1) … SP(n-1, n-1) SP_CoPrinter SP_CoScheduler For lifeG.c you have to include openGL libraries: gcc lifeG.c –lGL –lGLU –lglut –o life

שאלות חזרה למבחן

שאלה 1 עלינו לממש את קטע הקוד הבא: int a, b, x; x = blah(a,&b) מהו קטע הקוד שיבצע זאת נכון ? a) push a c) push dword b push b push dword [a] call blah call blah add esp, 8 add esp, 8 mov [x], eax mov [x], eax b) push dword [b] d) push dword [b] push dword a push dword a mov [x], eax pop dword [x]

שאלה 1 עלינו לממש את קטע הקוד הבא: int a, b, x; x = blah(a,&b) מהו קטע הקוד שיבצע זאת נכון ? a) push a c) push dword b push b push dword [a] call blah call blah add esp, 8 add esp, 8 mov [x], eax mov [x], eax b) push dword [b] d) push dword [b] push dword a push dword a mov [x], eax pop dword [x]

שאלה 3 איזה מקטעי הקוד הבאים יעבוד כ-Position Independent Code : bla: db ‘tab\0’ push bla call printf mov eax, 4 mov ebx, 1 mov ecx, dword [bla] int 0x80 mov eax, ‘bla\0’ call printf None of the above

שאלה 3 איזה מקטעי הקוד הבאים יעבוד כ-Position Independent Code : bla: db ‘tab\0’ push bla call printf mov eax, 4 mov ebx, 1 mov ecx, dword [bla] int 0x80 mov eax, ‘bla\0’ call printf None of the above

שאלה 4 עלינו לפנות מהזיכרון רשימה מקושרת ע"י שחרור כל האיברים שלה (בעזרת פונקציית free של C). ה-dword הראשון בכל רשומה הוא מצביע לרשומה הבאה. מצביע שערכו 0 הוא null pointer. נניח כי ecx מצביע לאיבר הראשון ברשימה. יש לממש את הקוד הנדרש.

שאלה 4 עלינו לפנות מהזיכרון רשימה מקושרת ע"י שחרור כל האיברים שלה (בעזרת פונקציית free של C). ה-dword הראשון בכל רשומה הוא מצביע לרשומה הבאה. מצביע שערכו 0 הוא null pointer. נניח כי ecx מצביע לאיבר הראשון ברשימה. יש לממש את הקוד הנדרש. תשובה free_list: cmp ecx, 0 jz end push [ecx] ; backup for the next pointer push ecx call free add esp, 4 pop ecx ; restore for the next pointer jmp free_list end: ret

שאלה 5 נתונות ההגדרות הבאות בייצוג Little Endian: x: db 10 y: db 3 מה יהיה ערכו (בייצוג הקסא-דצימלי) של הרגיסטר BX לאחר הפקודה: mov bx, [x]

שאלה 5 נתונות ההגדרות הבאות בייצוג Little Endian: x: db 10 y: db 3 מה יהיה ערכו (בייצוג הקסא-דצימלי) של הרגיסטר BX לאחר הפקודה: mov bx, [x] תשובה bx = 0x30A 0000 0011 0000 1010 0x0 0x3 0x0 0xA 0x30A

שאלה 6 ברצוננו לכתוב קוד לשימוש רב-פעמי, שמכפיל את ערך eax פי 3. מוצעות 2 אפשרויות: שימוש במקרו triple או קריאה לפונקציה Triple: %macro triple 0 mov ebx, eax add eax, eax add eax, ebx %endmacro Triple: mov ebx, eax add eax, eax add eax, ebx ret א) בזמן ריצה ל-2 האפשרויות אותו זמן ביצוע. ב) השימוש ב- macro מהיר יותר, אבל דורש יותר זיכרון לקוד. ג) השימוש בפונקציה מהיר יותר, אבל דורש יותר זיכרון לקוד. ד) הפונקציה Triple לא יכולה לעבוד, כי היא לא מוציאה משתנים מהמחסנית

שאלה 6 ברצוננו לכתוב קוד לשימוש רב-פעמי, שמכפיל את ערך eax פי 3. מוצעות 2 אפשרויות: שימוש במקרו triple או קריאה לפונקציה Triple: %macro triple 0 mov ebx, eax add eax, eax add eax, ebx %endmacro Triple: mov ebx, eax add eax, eax add eax, ebx ret א) בזמן ריצה ל-2 האפשרויות אותו זמן ביצוע. ב) השימוש ב- macro מהיר יותר, אבל דורש יותר זיכרון לקוד. ג) השימוש בפונקציה מהיר יותר, אבל דורש יותר זיכרון לקוד. ד) הפונקציה Triple לא יכולה לעבוד, כי היא לא מוציאה משתנים מהמחסנית

שאלה 7 עלינו להחליף בין ערכי המשתנים L ו- L1 המוגדרים בצורה הבאה: שאלה 7 עלינו להחליף בין ערכי המשתנים L ו- L1 המוגדרים בצורה הבאה: L: dw 7 L1: dw 0xF7AC אילו מקטעי הקוד הבאים לא יבצע את זאת כנדרש? mov ax, [L] c) mov eax, [L1] mov bx, [L1] rol eax, 16 mov [L1], ax mov [L1], eax mov [L], bx mov eax, [L] d) mov eax, [L] rol eax, 16 xor ax, [L1] mov [L], eax xor [L], ax xor [L1], ax

שאלה 7 עלינו להחליף בין ערכי המשתנים L ו- L1 המוגדרים בצורה הבאה: L: dw 7 L1: dw 0xF7AC אילו מקטעי הקוד הבאים לא יבצע את זאת כנדרש mov ax, [L] c) mov eax, [L1] mov bx, [L1] rol eax, 16 mov [L1], ax mov [L1], eax mov [L], bx mov eax, [L] d) mov eax, [L] rol eax, 16 xor ax, [L1] mov [L], eax xor [L], ax xor [L1], ax

שאלה 8 נתון מבנה נתונים המוגדר באופן הבא: bla: dd bla + 8, bla + 16, bla + 24, bla + 32, bla + 24, 0, 0, 0, 0, 0 כמו כן נתון הקוד של פונקציה Foo: Foo: cmp ebx, 0 jz End inc ecx push ebx mov ebx, dword [ebx + 4] call Foo pop ebx mov ebx, dword [ebx] call Foo End: ret מה יהיה ערכו של ecx לאחר קריאה ל-Foo כאשר ערכו של ebx לפני הקריאה היה bla וערכו של ecx היה 0? מה יהיה ערכו של ecx לאחר קריאה ל-Foo כאשר ערכו של ebx לפני הקריאה היה bla+4 וערכו של ecx היה 0?

תשובה נספור את פעולות ה- inc עבור ערכי EBX שונים תשובה נספור את פעולות ה- inc עבור ערכי EBX שונים. נשים לב כי ישנם 2 קריאות רקורסיביות. לכן, נדאג לכך שמספר פעולות ה- inc יחושב עבורם מוקדם יותר (כלומר נבצע את הסכימה מ"למטה למעלה") ונוסיף לכך פעולת inc אחת המתבצעת בפונקציה, נמשיך באופן זה עד שנגיע לבעיה המקורית: foo(EBX=0) = 0 ; stop condition foo(EBX=bla+X) = 1 where X>=20 foo(EBX=bla+16) = foo(EBX=0) + foo(EBX=bla+24) + 1 = 2 foo(EBX=bla+12) = foo(EBX=bla+24) + foo(EBX=bla+32) + 1 = 3 foo(EBX=bla+8) = foo(EBX=bla+32) + foo(EBX=bla+24) + 1 = 3 foo(EBX=bla+4) = foo(EBX=bla+24) + foo(EBX=bla+16) + 1 = 5 foo(EBX=bla) = foo(EBX=bla+16) + foo(EBX=bla+8) + 1 = 6 מכאן שעבור סעיף ראשון ecx=6 ועבור סעיף שני ecx=5.