Difference between revisions of "CSC231 Exercises with the MOV instruction"
(Created page with "--~~~~ ---- =Problem #1= <br /> Translate this program in a language close to Java and C/C++, into assembly <br /> <source lang="java"> int Table1[5] = { 1, 10, 20, 30, 40...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
// some assignments | // some assignments | ||
+ | Table1[0] = Table2[0] | ||
+ | |||
Table2[0] = 3; | Table2[0] = 3; | ||
Table2[1] = 4; | Table2[1] = 4; | ||
Line 18: | Line 20: | ||
Table2[4] = 10; | Table2[4] = 10; | ||
− | Table1[0] = | + | Table1[0] = Table2[0] |
− | Table1[1] = | + | Table1[1] = Table2[4] |
msg2[0] = msg1[0]; | msg2[0] = msg1[0]; | ||
Line 29: | Line 31: | ||
How long does it take a 1GHz Pentium to execute the section labeled "some assignments"? | How long does it take a 1GHz Pentium to execute the section labeled "some assignments"? | ||
<br /> | <br /> | ||
+ | |||
+ | =Problem 3= | ||
+ | <br /> | ||
+ | * Draw the RAM, store the variables that are declared in the program below, and show how the RAM and the registers get modified by each instruction. | ||
+ | <br /> | ||
+ | <source lang="asm"> | ||
+ | x dd 0x11223344 | ||
+ | y dw 0x1234, 0xffff, 0, 1 | ||
+ | z db "hello", 10, 10 | ||
+ | |||
+ | mov eax, dword[x] | ||
+ | mov al, 0 | ||
+ | mov dword[x], eax | ||
+ | |||
+ | mov ax, word[y] | ||
+ | mov dword[x], eax | ||
+ | |||
+ | mov bx, word[y+2] | ||
+ | mov word[y], bx | ||
+ | |||
+ | mov al, 'X' | ||
+ | mov byte[z], al | ||
+ | mov byte[z+1], al | ||
+ | mov byte[z+2], al | ||
+ | |||
+ | |||
+ | </source> | ||
+ | <br /> | ||
+ | |||
+ | =Problem #4= | ||
<br /> | <br /> | ||
+ | Same as Problem #3, but with much more complex instructions.<br /> | ||
+ | <br /> | ||
+ | <source lang="asm"> | ||
+ | x dd 0x11223344 | ||
+ | y dw 0x1234, 0xffff, 0, 1 | ||
+ | z db "hello", 10, 10 | ||
+ | |||
+ | mov eax, dword[x] | ||
+ | mov dword[y], eax | ||
+ | |||
+ | mov ebx, dword[y+1] | ||
+ | mov word[x], bx | ||
+ | |||
+ | mov edx, 0 | ||
+ | mov dx, word[z] | ||
+ | mov dword[z], edx | ||
+ | |||
+ | mov al, 'X' | ||
+ | mov byte[z], al | ||
+ | mov byte[z+1], al | ||
+ | mov byte[z+2], al | ||
+ | |||
+ | |||
+ | </source> | ||
+ | |||
<br /> | <br /> | ||
<br /> | <br /> |
Latest revision as of 15:15, 28 September 2015
--D. Thiebaut (talk) 12:58, 28 September 2015 (EDT)
Contents
Problem #1
Translate this program in a language close to Java and C/C++, into assembly
int Table1[5] = { 1, 10, 20, 30, 40};
int Table2[5];
String msg1 = "Hello world!";
String msg2 = " ";
// some assignments
Table1[0] = Table2[0]
Table2[0] = 3;
Table2[1] = 4;
Table2[2] = 5;
Table2[3] = 6;
Table2[4] = 10;
Table1[0] = Table2[0]
Table1[1] = Table2[4]
msg2[0] = msg1[0];
msg1[11] = '\n';
Problem #2
How long does it take a 1GHz Pentium to execute the section labeled "some assignments"?
Problem 3
- Draw the RAM, store the variables that are declared in the program below, and show how the RAM and the registers get modified by each instruction.
x dd 0x11223344
y dw 0x1234, 0xffff, 0, 1
z db "hello", 10, 10
mov eax, dword[x]
mov al, 0
mov dword[x], eax
mov ax, word[y]
mov dword[x], eax
mov bx, word[y+2]
mov word[y], bx
mov al, 'X'
mov byte[z], al
mov byte[z+1], al
mov byte[z+2], al
Problem #4
Same as Problem #3, but with much more complex instructions.
x dd 0x11223344
y dw 0x1234, 0xffff, 0, 1
z db "hello", 10, 10
mov eax, dword[x]
mov dword[y], eax
mov ebx, dword[y+1]
mov word[x], bx
mov edx, 0
mov dx, word[z]
mov dword[z], edx
mov al, 'X'
mov byte[z], al
mov byte[z+1], al
mov byte[z+2], al