Computer Architecture and Assembly Language

Slides:



Advertisements
Similar presentations
COMP 2003: Assembly Language and Digital Logic
Advertisements

Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 2 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Computer Organization & Assembly Language
Irvine, Kip R. Assembly Language For Intel-Based Computers TYPE and SIZE Operators TYPE –returns the size, in bytes of a single element of a data label.
Assembly 02. Outline mov Command Registers Memory EFLAGS Arithmetic 1.
Computer Organization And Assembly Language
Practical Session 3 Computer Architecture and Assembly Language.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
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.
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 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
Practical Session 2. Labels Definition valid characters in labels are: letters, numbers, _, $, ~,., and ? first character can be: letter, _, ? and.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
ELF binary # readelf -a foo.out ELF Header:
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Practical Session 4 Computer Architecture and Assembly Language.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
Assembly 06. Outline cmp (review) Jump commands test mnemonic bt mnemonic Addressing 1.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Practical Session 6 Computer Architecture and Assembly Language.
Practical Session 2 Computer Architecture and Assembly Language.
Practical Session 3 Computer Architecture and Assembly Language.
Practical Session 3.
Practical Session 5.
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
Practical Session 2.
Computer Architecture and Assembly Language
Microprocessor Architecture
Aaron Miller David Cohen Spring 2011
Microprocessor and Assembly Language
Chapter 3 Bit Operations
Assembly IA-32.
Assembly Language Programming Part 2
Practical Session 7.
Computer Architecture and Assembly Language
Chapter 4: Instructions
Practical Session 2.
Computer Architecture and Assembly Language
Practical Session 9.
CS-401 Computer Architecture & Assembly Language Programming
Practical Session 4.
Shift & Rotate Instructions)
Computer Architecture and Assembly Language
CET 3510 – Lecture 11 Bit Manipulation in a High-Level Programming Language Dr. José M. Reyes Álamo.
Multi-modules programming
Shift, Multiply, and Divide
X86 Assembly Review.
Computer Architecture and System Programming Laboratory
CSC 497/583 Advanced Topics in Computer Security
CS-401 Computer Architecture and Assembly Language Programming
ICS51 Introductory Computer Organization
Computer Architecture and System Programming Laboratory
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
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 13 שאלות חזרה למבחן

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

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

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

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

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

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

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

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

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

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

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

שאלה 8 דרוש לבצע חיבור של שני מספרים של 32 BIT על מעבד 68040 (רוחב 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

שאלה 8 דרוש לבצע חיבור של שני מספרים של 32 BIT על מעבד 68040 (רוחב 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

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

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

3 19