Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Architecture and Assembly Language

Similar presentations


Presentation on theme: "Computer Architecture and Assembly Language"— Presentation transcript:

1 Computer Architecture and Assembly Language
Practical Session 13 שאלות חזרה למבחן

2 שאלה 1 נתונות ההגדרות הבאות: x: dw 1 y: db 2 z: db 3
יש להכפיל את x, y, z ב 2 באמצעות פקודה אחת. ניתן להניח שאין overflow תשובה: נכפול את כל המילה ב 2 shl dword [x], 1

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

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

5 שאלה 3 עלינו לממש קריאה לפונקציה ללא ארגומנטים. שכתובתה נמצאת ברגיסטר eax .יש לסמן את הקוד שלא יבצע זאת נכון . push next_a push eax ret next_a: push eax push eax ret push next_a jmp eax next_a: call eax

6 שאלה 3 עלינו לממש קריאה לפונקציה ללא ארגומנטים. שכתובתה נמצאת ברגיסטר eax .יש לסמן את הקוד שלא יבצע זאת נכון . push next_a push eax ret next_a: push eax push eax ret push next_a jmp eax next_a: call eax

7 שאלה 4 נתונה הגדרת macro הבאה, וכן נתונים בזכרון:
%macro print 3 pusha mov eax, 4 ; write mov ebx, %1 ; file descriptor mov ecx, %2 ; address mov edx, %3 ; byte count int 0x80 popa %endmacro section .rodata File: dd 1 MJ: db “Beat it”, 10, 0 איזה מהשימושים הבאים במקרו יגרום לפעולה לא נכונה של התוכנית: mov ebx, MJ print 1, ebx, 9 print 1, MJ, 9 print dword [File], MJ, 9 mov edx, 9 print 1, MJ, edx

8 שאלה 4 נתונה הגדרת macro הבאה, וכן נתונים בזכרון:
%macro print 3 pusha mov eax, 4 ; write mov ebx, %1 ; file descriptor mov ecx, %2 ; address mov edx, %3 ; byte count int 0x80 popa %endmacro section .rodata File: dd 1 MJ: db “Beat it”, 10, 0 איזה מהשימושים הבאים במקרו יגרום לפעולה לא נכונה של התוכנית: mov ebx, MJ print 1, ebx, 9 print 1, MJ, 9 print dword [File], MJ, 9 mov edx, 9 print 1, MJ, edx

9 שאלה 5 ברגיסטר eax נמצא הערך -1 יש לרשום 5 פקודות שונות שכל אחת מהן תגרום לכך שברגיסטר eax יהיה הערך 1 תשובה mov eax, 1 add eax, 2 neg eax shr eax, 31 and eax, 1

10 שאלה 6 מה תחזיר הפונקציה Gloat ברגיסטר ebx (עבור ebx בין 0 ל- 3) ?
א) 0 ב) ebx בחזקת 2 ג) 2 בחזקת ebx ד) ebx כפול 2 Gloat: shl ebx, 2 jmp [ebx+Tab] Tab: dd F4 dd F3 dd F2 dd F1 F1: add ebx, 4 F2: add ebx, 4 F3: add ebx, 4 F4: shr ebx, 2 ret

11 שאלה 6 מה תחזיר הפונקציה Gloat ברגיסטר ebx (עבור ebx בין 0 ל- 3) ?
א) 0 ב) ebx בחזקת 2 ג) 2 בחזקת ebx ד) ebx כפול 2 Gloat: shl ebx, 2 jmp [ebx+Tab] Tab: dd F4 dd F3 dd F2 dd F1 F1: add ebx, 4 F2: add ebx, 4 F3: add ebx, 4 F4: shr ebx, 2 ret ebx = 0  shl 0,2 = 0 jmp [0+Tab] = jmp F4 shr 0, 2 = 0  ebx = 0 ebx = 1  shl 1,2 = 1*2*2 = 4 jmp [4+Tab] = jmp F3 F3: add 4, 4 = 8 shr 8, 2 = 8/2/2 = 2  ebx = 2 ebx = 2  shl 2,2 = 2*2*2 = 8 jmp [8+Tab] = jmp F2 F2: add 8, 4 = 12 F3: add 12, 4 = 16 shr 16, 2 = 16/2/2 = 4  ebx = 4 ebx = 3  shl 3,2 = 3*2*2 = 12 jmp [12+Tab] = jmp F1 F1: add 12, 4 = 16 F2: add 16, 4 = 20 F3: add 20, 4 = 24 shr 24, 2 = 24/2/2 = 6  ebx = 6

12 שאלה 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

13 שאלה 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 RAM 0x?? 0xF7 0xAC 0x00 0x07 L1 mov ax, [L]  ax = 0x00 0x07 mov bx, [L1]  bx = 0xF7 0xAC mov [L1], ax  [L1] = 0x07 , [L1+1] = 0x00 mov [L], bx  [L] = 0xAC , [L+1] = 0xF7 L mov eax, [L]  eax = 0xF7 0xAC 0x00 0x07 rol eax, 16  eax = 0x00 0x07 0xF7 0xAC mov [L], eax  [L] = 0xAC , [L+1] = 0xF7 , [L1] = 0x07 , [L1+1] = 0x00 mov eax, [L1]  eax = 0x?? 0x?? 0xF7 0xAC rol eax, 16  eax = 0xF7 0xAC 0x?? 0x?? mov [L1], eax  [L1] = 0x?? , [L1+1] = 0x?? mov eax, [L]  eax = 0xF7 0xAC 0x00 0x07 xor ax, [L1]  ax = 0x0007 xor 0xF7AC = 0xF7AB xor [L], ax  [L] = 0x0007 xor 0xF7AB = 0xF7AC xor [L1], ax  [L1] = 0xF7AC xor 0xF7AB = 0x0007

14 שאלה 8 דרוש לבצע חיבור של שני מספרים של 32 BIT על מעבד (רוחב BUS של 32 BIT). פקודת חיבור שני אופרנדים בזכרון מותרת במעבד זה. ייצוג המספרים הוא BIG ENDIAN, וכל אופרנד באורך N חייב להתחיל בכתובת המתחלקת ב N (alignment). המספרים נמצאים בזכרון בכתובת X ו Y, והתוצאה צריכה להיות ב Y. (X הוא משתנה שמשתרע על איזור X_HIGH ֹ וגם X_LOW). איזו מהתוכניות הבאות תוכל לבצע את הנדרש ? align 4 A: dw 0 X: X_HIGH: dw 5 ; dw reserves space for 2 byte “variable” X_LOW: dw 10 JUNK: dw 0 Y: dl 700 ; dl reserves space for 4 byte “variable” ADD.W X, Y ; add word at address X in ; memory into word at address Y ADDX.W X+2, Y+2 ; add word at X+2 in memory into ; word at Y+2 in memory with extend flag (like CF) ADD.W X+2, Y+2 ADDX.W X, Y MOVE.L X, D0 ; move longword (32 bits) at X to register D0 ADD.L D0, Y ; add D0 to Y ADD.L X, Y ; add longword X to Y

15 שאלה 8 דרוש לבצע חיבור של שני מספרים של 32 BIT על מעבד (רוחב BUS של 32 BIT). פקודת חיבור שני אופרנדים בזכרון מותרת במעבד זה. ייצוג המספרים הוא BIG ENDIAN, וכל אופרנד באורך N חייב להתחיל בכתובת המתחלקת ב N (alignment). המספרים נמצאים בזכרון בכתובת X ו Y, והתוצאה צריכה להיות ב Y. (X הוא משתנה שמשתרע על איזור X_HIGH ֹ וגם X_LOW). איזו מהתוכניות הבאות תוכל לבצע את הנדרש ? align 4 A: dw 0 X: X_HIGH: dw 5 ; dw reserves space for 2 byte “variable” X_LOW: dw 10 JUNK: dw 0 Y: dl 700 ; dl reserves space for 4 byte “variable” ADD.W X, Y ; add word at address X in ; memory into word at address Y ADDX.W X+2, Y+2 ; add word at X+2 in memory into ; word at Y+2 in memory with extend flag (like CF) ADD.W X+2, Y+2 ADDX.W X, Y MOVE.L X, D0 ; move longword (32 bits) at X to register D0 ADD.L D0, Y ; add D0 to Y ADD.L X, Y ; add longword X to Y a) Y_HIGH += X_HIGH Y_LOW + = X_LOW + CF b) Y_LOW + = X_LOW Y_HIGH += X_HIGH+ CF d) ADD.L is not legal by the same reason as MOVE.L RAM 0xBC 0x02 0x00 0x0A 0x05 12 700d = 0x2BC 11 10 9 8 y 7 6 JUNK 5 4 X_LOW 3 2 X≡ X_HIGH align 4  move to a closest address in appropriate memory section which is %4 = 0 1 c) MOVE.L is not legal since its X operand is in memory and of size L(longword = 4 bytes), so X should begin in memory at address that %4 = 0. X begins in memory at address with offset 2 from some address that is divided by 4, so X’s address is not divided by 4. A

16 שאלה 9 ברצוננו לכתוב קוד לשימוש רב-פעמי, שמכפיל את ערך 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 לא יכולה לעבוד, כי היא לא מוציאה משתנים מהמחסנית

17 שאלה 9 ברצוננו לכתוב קוד לשימוש רב-פעמי, שמכפיל את ערך 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 לא יכולה לעבוד, כי היא לא מוציאה משתנים מהמחסנית

18

19

20 3 19

21


Download ppt "Computer Architecture and Assembly Language"

Similar presentations


Ads by Google