代写代考 Practical – Assembly Language

Practical – Assembly Language
Configure Visual studio for MASM and implement the following basic programs by following the instructions in the documents provided:
– Implementing and working with MASM programming.doc
– MASM Visual Studio.doc

Copyright By PowCoder代写 加微信 powcoder

Part 1 – Arithmetic
Write the following C program in assembly language.
int a = 11;
int b = 3;
a = a + b;
a = a – b;
a = a * 2;
b = a % 3;
Here is some code to initialise the variables a and b:
; write your assembly code here
mov dword ptr [ebp-4], 11 ; int a = 11 movdwordptr[ebp-8],3 ;intb=3
mov dword ptr [ebp-4], 11 ; int a = 11 movdwordptr[ebp-8],3 ;intb=3
mov eax, [ebp-4]
add eax, [ebp-8]
mov [ebp-4], eax
mov ecx, [ebp-4]
sub ecx, [ebp-8]
mov [ebp-4], ecx
mov edx, [ebp-4]
mov [ebp-4], edx
mov eax, [ebp-8]
mov [ebp-8], eax
mov eax, [ebp-4]
mov ecx, 2
mov [ebp-4], eax
mov edx, 0
mov eax, [ebp-4]
mov ecx, 3
mov [ebp-8], edx
; move a into eax ;addaandb ;a=a+b
; move a into ecx ;subbfroma ;a=a-b
; move a into edx
; decrement a by 1
; store edx
; move b into eax
; increment b by 1
; store eax
; mov a into eax register ; mov 2 into ecx register ; multiply a by 2 ;a=a*2
; clear edx dividend register
; move a into eax register
; move 3 into ecx register ;ecx=eax/ecxi.e.ecx=a/3
; (division in eax, remainder in edx)

Part 2 – Nested IF statements
Write the following C program in assembly language. What is the final value for z?
Hex = FFFFFFFE
Experiment with different values for x, y and z so that all paths are covered.
int x = 0;
int y = 1;
int z = 2;
if (x == y){
if(z == 0){
if(z == 0){
When implementing jump statements you need to provide a label.
For example, jmp l1 will result in the program jumping to the line labelled l1 e.g.
l1: # code jumps to here
See lecture notes for more examples.

mov dword ptr [ebp-4], 0 ; int x = 0 mov dword ptr [ebp-8], 1 ; int y = 1 mov dword ptr [ebp-0Ch], 2 ; int z = 2
mov eax, [ebp-4] mov ebx, [ebp-8] cmp eax, ebx
cmp dword ptr [ebp-0Ch], 0
mov eax, [ebp-0Ch]
add eax, [ebp-8]
mov [ebp-0Ch], eax
mov eax, [ebp-8]
sub eax, [ebp-0Ch]
mov [ebp-0Ch], eax
cmp dword ptr [ebp-0Ch],0
mov eax, [ebp-0Ch]
add eax, [ebp-4]
mov [ebp-0Ch], eax
mov eax, [ebp-4]
sub eax, [ebp-0Ch]
mov [ebp-0Ch], eax
INVOKE ExitProcess, 0
; move x into eax register
; move y into ebx register
; compare x with y and if the same Zf = 1 ;jumptol2ifZf=0
; compare z with 0 if same set Zf = 1
; jump to l21
; move z into ;addzandy ;z=z+y
ifZf=0 eax register
; jump to label l1
; move y into eax register ;subtracty-z ;z=y-z
; jump to l1
; compare z with 0 and if same set Zf = 1 ;jumptol22ifZf=0
; move z into eax register ;addx+z
; move x into eax register ;subx-z
Answer Part2

Part 3 – For loops
Implement the following C program in assembly language.
What is the final value of j? Hex – 2d
for (i = 0; i < 10; i++) Answer Part 3 mov dword ptr [ebp-4], 0 mov dword ptr [ebp-8], 0 mov eax, [ebp-4] add eax, 1 mov [ebp-4], eax cmp dword ptr [ebp-4], 10 jge l2 mov eax, [ebp-4] mov ebx, [ebp-8] add ebx, eax mov [ebp-8], ebx INVOKE ExitProcess, 0 ; int i = 0 ; int j = 0 ; move i into eax register ; move i into eax register ; move j into ebx register ; addj+i Part 4 – While Loops Implement the following C program in assembly language. What is the final value of p? Hex - 800 Dec - 2048 int p = 2; int r = 3; int n = 5; int y = 1; while (y <= n) p = p*(1+r); Answer Part 4 mov dword ptr [ebp-4],2 mov dword ptr [ebp-8],3 mov dword ptr [ebp-0Ch],5 mov dword ptr [ebp-10h],1 mov eax, [ebp-10h] cmp eax, dword ptr [ebp-0Ch] mov ecx, [ebp-8] add ecx, 1 mov eax, [ebp-4] ; movey=1into ; whiley<=n ; jumptol2ify ; move r into ecx ; move p into eax ; multiply p * (1 ; p=p*(1+r) ; move y into eax mov [ebp-4], eax mov eax, [ebp-10h] mov [ebp-10h], eax ; jmp l1 INVOKE ExitProcess, 0 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com