computer architecture and system programming...

21
TA Sessions 13+14 שאלות חזרה למבחןComputer Architecture and System Programming Laboratory

Upload: others

Post on 18-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

TA Sessions 13+14שאלות חזרה למבחן

Computer Architecture and

System Programming Laboratory

Page 2: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

1שאלה

:נתונות ההגדרות הבאותx: dw 1y: db 2z: db 3

ניתן .באמצעות פקודה אחת2ב x, y, zיש להכפיל את overflowלהניח שאין

Page 3: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

1שאלה

:נתונות ההגדרות הבאותx: dw 1y: db 2z: db 3

ניתן .באמצעות פקודה אחת2ב x, y, zיש להכפיל את overflowלהניח שאין

2נכפול את כל המילה ב :תשובה

shl dword [x], 1

Page 4: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

eaxשכתובתה נמצאת ברגיסטר .עלינו לממש קריאה לפונקציה ללא ארגומנטים

.יבצע זאת נכון לאיש לסמן את הקוד ש.

a) push next_a

push eax

ret

next_a:

b) push eax

push eax

ret

c) push next_a

jmp eax

next_a:

d) call eax

2שאלה

Page 5: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

eaxשכתובתה נמצאת ברגיסטר .עלינו לממש קריאה לפונקציה ללא ארגומנטים

.יבצע זאת נכון לאיש לסמן את הקוד ש.

a) push next_a

push eax

ret

next_a:

b) push eax

push eax

ret

c) push next_a

jmp eax

next_a:

d) call eax

2שאלה

Page 6: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

3שאלה

:נתונות ההגדרות הבאות x: db 10y: db 3

של ( דצימלי-בייצוג הקסא)מה יהיה ערכו :לאחר הפקודהBXהרגיסטר

mov bx, [x]

Page 7: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

3שאלה

:נתונות ההגדרות הבאות x: db 10y: db 3

של ( דצימלי-בייצוג הקסא)מה יהיה ערכו :לאחר הפקודהBXהרגיסטר

mov bx, [x]

תשובהbx = 0x30A

Page 8: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

4שאלה :בזכרוןוכן נתונים , הבאהmacroנתונה הגדרת

%macro print 3pushadmov eax, 4mov ebx, %1mov ecx, %2mov edx, %3int 0x80popad

%endmacrosection .rodataFile: dd 1MJ: db “Beat it”, 10, 0

:איזה מהשימושים הבאים במקרו יגרום לפעולה לא נכונה של התוכנית

a) mov ebx, MJprint 1, ebx, 8

b) print 1, MJ, 8c) print dword [File], MJ, 8d) mov edx, 8

print 1, MJ, edx

Page 9: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

:בזכרוןוכן נתונים , הבאהmacroנתונה הגדרת

%macro print 3pushadmov eax, 4 ; writemov ebx, %1 ; file descriptormov ecx, %2 ; addressmov edx, %3 ; byte countint 0x80popad

%endmacrosection .rodataFile: dd 1MJ: db “Beat it”, 10, 0

:איזה מהשימושים הבאים במקרו יגרום לפעולה לא נכונה של התוכנית

a) mov ebx, MJprint 1, ebx, 8

b) print 1, MJ, 8c) print dword [File], MJ, 8d) mov edx, 8

print 1, MJ, edx

4שאלה

Page 10: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

5שאלה

?( 3-ל0בין ebxעבור ) ebxברגיסטר Gloatמה תחזיר הפונקציה

2כפול ebx( דebxבחזקת 2( ג2בחזקת ebx( ב0( א

Gloat: shl ebx, 2jmp [ebx+Tab]

Tab: dd F4dd F3dd F2dd F1

F1: add ebx, 4F2: add ebx, 4F3: add ebx, 4F4: shr ebx, 2

ret

Page 11: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

5שאלה

?( 3-ל0בין ebxעבור ) ebxברגיסטר Gloatמה תחזיר הפונקציה

2כפול ebx( דebxבחזקת 2( ג2בחזקת ebx( ב0( א

Gloat: shl ebx, 2jmp [ebx+Tab]

Tab: dd F4dd F3dd F2dd F1

F1: add ebx, 4F2: add ebx, 4F3: add ebx, 4F4: 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

Page 12: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

6שאלה L: dw 7:המוגדרים בצורה הבאהL1-וLעלינו להחליף בין ערכי המשתנים

L1: dw 0xF7AC

?יבצע את זאת כנדרש לאאילו מקטעי הקוד הבאים

a) mov ax, [L] c) mov eax, [L1]

mov bx, [L1] rol eax, 16

mov [L1], ax mov [L1], eax

mov [L], bx

b) mov eax, [L] d) mov eax, [L]

rol eax, 16 xor ax, [L1]

mov [L], eax xor [L], ax

xor [L1], ax

Page 13: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

6שאלה L: dw:המוגדרים בצורה הבאהL1-וLעלינו להחליף בין ערכי המשתנים

7

L1: dw 0xF7AC

?יבצע את זאת כנדרש לאאילו מקטעי הקוד הבאים

a) mov ax, [L] c) mov eax, [L1]

mov bx, [L1] rol eax, 16

mov [L1], ax mov [L1], eax

mov [L], bx

b) mov eax, [L] d) mov eax, [L]

rol eax, 16 xor ax, [L1]

mov [L], eax xor [L], ax

xor [L1], ax

RAM

0x??

0x??

0xF7

0xAC

0x00

0x07

a) 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

L1

L

b) 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

c) mov eax, [L1] → eax = 0x?? 0x?? 0xF7 0xAC

rol eax, 16 → eax = 0xF7 0xAC 0x?? 0x??

mov [L1], eax → [L1] = 0x?? , [L1+1] = 0x??

d) 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

Page 14: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

section .data

format_string: dw ’H’, ’e’, ’l’, ’l’, ’o’, 10, 0

extern exit, printf

global main

section .text

main:

push dword format_string

call printf

add esp, 4

mov eax, 0

call exit

?מהו הפלט של קטע קוד הבא

7שאלה

Page 15: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

section .data

format_string: dw ’H’, ’e’, ’l’, ’l’, ’o’, 10, 0

extern exit, printf

global main

section .text

main:

push dword format_string

call printf

add esp, 4

mov eax, 0

call exit

Answer: The single letter ’H’. Because the format string is a dw rather

than a db, and because the x86 architecture is little-endian, the string

"terminates" after the first character, even though 14 bytes are reserved.

?מהו הפלט של קטע קוד הבא

7שאלה

Page 16: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

8שאלה

Page 17: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

8שאלה

Page 18: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

9שאלה

Page 19: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

9שאלה

Page 20: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

10שאלה

Page 21: Computer Architecture and System Programming Laboratorycaspl202/wiki.files/assign4/PS13and14_ca… · System Programming Laboratory. 1 הלאש :תואבה תורדגהה תונותנ

10שאלה