Lab 10 - Assembly Language for x86 Processors by KIP R. IRVINE
HTML-код
- Опубликовано: 1 дек 2024
- Topics: Advanced Procedures, Local Variables
.
Sample Code 01:
TITLE
; Name:
; Date:
; ID:
; Description:
INCLUDE Irvine32.inc
INCLUDELIB Irvine32.lib
; these two lines are only necessary if you're not using Visual Studio
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
.data
myArray BYTE 10 DUP (0)
fillValue DWORD 5
arraySize DWORD 10
.code
FillArray PROC uses eax ecx
LOCAL t1:DWORD, D1:DWORD
;push ebp
;mov ebp, esp
;sub esp, 8
Enter 8,0
;push edx
;push ecx
;push eax
mov t1, 5
mov D1, 3
mov edi, t1
add edi, D1
mov DWORD PTR [EBP-4], 4
mov DWORD PTR [EBP-8], 3
mov edx, [EBP-4]
add edx, [EBP-8]
call dumpregs
mov ecx, [ebp+16]
mov esi, [ebp+8]
mov eax, [ebp+12]
l1:
mov [esi], eax
inc esi
loop l1
;pop eax
;pop ecx
;pop edx
;mov esp, ebp
;pop ebp
leave
ret 12
FillArray ENDP
main PROC
mov esi, offset myArray
mov ecx, lengthof myArray
mov ebx, type myArray
call dumpmem
push arraySize
push fillValue
push offset myArray
call FillArray
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sample Code 02:
TITLE
; Name:
; Date:
; ID:
; Description:
INCLUDE Irvine32.inc
INCLUDELIB Irvine32.lib
; these two lines are only necessary if you're not using Visual Studio
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
.data
myArray BYTE 10 DUP(0) ; Array with 10 elements initialized to 0
fillValue DWORD 5 ; Value to fill in the array
arraySize DWORD 10 ; Size of the array
.code
FillArray PROC
; Parameters are passed via the stack:
; pArray = [ESP+4]
; fillVal = [ESP+8]
; arraySize = [ESP+12]
push ebp ; Save base pointer
mov ebp, esp ; Establish stack frame
mov ecx, [ebp+16] ; Load arraySize into ECX (loop counter)
mov esi, [ebp+8] ; Load address of the array (pArray) into ESI
mov eax, [ebp+12] ; Load the fill value into AL
L1: mov [esi], eax ; Store the fill value at the address ESI points to
inc esi ; Increment ESI to point to the next byte
loop L1 ; Decrement ECX and repeat until it reaches 0
mov esi, offset myArray
mov ecx, lengthof myArray
mov ebx, type myArray
call dumpmem
pop ebp ; Restore base pointer
ret ; Return to the caller
FillArray ENDP
main PROC
mov esi, offset myArray
mov ecx, lengthof myArray
mov ebx, type myArray
call dumpmem
; Manually push arguments onto the stack for the FillArray procedure
push arraySize ; Push arraySize (3rd argument)
push fillValue ; Push fillValue (2nd argument)
push OFFSET myArray ; Push the address of myArray (1st argument)
; Call FillArray procedure
CALL FillArray ; Call FillArray (pArray, fillValue, arraySize)
exit
main ENDP
END main
mov esi, offset myArray
mov ecx, lengthof myArray
mov ebx, type myArray
call dumpmem
exit
main ENDP
END main