Lab 5
Lab 5
Example 1
.data
; define your variables here
.code
main PROC
; write your assembly code here
INVOKE ExitProcess, 0
main ENDP
END main
Example 2
Locate the first nonzero value in the array. If none is found, let ESI point to the sentinel value:
.data
array SWORD 50 DUP(?)
sentinel SWORD 0FFFFh
.code
mov esi,OFFSET array mov ecx,LENGTHOF array
L1: cmp WORD PTR [esi],0 ; check for zero
(fill in your code here)
quit:
Solution
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode: DWORD
.data
; define your variables here
.code
main PROC
; write your assembly code here
INVOKE ExitProcess, 0
main ENDP
END main
Conditional Structures
Example 3
Assembly language programmers can easily translate logical statements written in C++/Java into
assembly language.
For example:
X = 1;
else
X = 2;
Example 4
Implement the following pseudocode in assembly language. All values are unsigned:
Example 5
But the following implementation uses 29% less code by reversing the first relational operator. We
allow the program to “fall
fall through" to the second expression:
next:
Example 6:
Implement the following pseudocode in assembly language. All values are unsigned:
(There are multiple correct solutions to this problem.)
A WHILE loop is really an IF statement followed by the body of the loop, followed by an unconditional
jump to the top of the loop. Consider the following example:
next:
Example 9: Implement the following loop, using unsigned 32
32-bit integers:
next:
else:
_endwhile: