-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryAddressing_.asm
More file actions
77 lines (63 loc) · 1.7 KB
/
MemoryAddressing_.asm
File metadata and controls
77 lines (63 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
.model flat,c
; Simple lookup table
.const
FibNumbers dword 0, 1, 1, 2, 3, 5, 8 13
dword 21, 34, 55, 89, 144, 233, 377, 610
NumFib_ dword ($ - FibNumbers) / sizeof dword
public NumFib_
; extern "C" MemoryAddressing_(int i, int* v1, int* v2, int* v3, int* v4);
;
; Description: Show the addressing memory with access to operants in memory
;
;
; Returns: 0 Error
; 1 Success
.code
MemoryAddressing_ proc
push ebp
mov ebp,esp
push ebx
push esi
push edi
; Check if 'i' is valid
xor eax,eax
mov ecx,[ebp+8] ; ecx = i
cmp ecx,0
jl InvalidIndex ; jump if i < 0
cmp ecx,[NumFib_]
jge InvalidIndex ; jump if >=NumFib_
; Example 1 - base register
mov ebx,offset FibNumbers ; ebx = FibNumbers
mov esi.[ebp+8] ; esi = i
shl esi,2 ; esi= i*4
add ebx,asi ; ebx = FibNumbers + i * 4
mov eax,[ebx] ; Load table value
mov [edi],eax ; Save to 'v1'
; Example 2 - base register + displacement
mov esi,[ebp+8] ; esi = i
shl esi,2 ; esi = i * 4
mov eax,[esi+FibNumbers] ; Load table value
mov edi,[ebp+16]
mov [edi], eax ; Save to 'v2'
; Example 3 - base register + index register
mov ebx,offset FibNumbers ; ebx = FibNumbers
mov esi,2 ; esi = i
shl esi,2 ; esi = i * 4
mov eax,[ebx+esi] ; Load table value
mov edi,[ebp+20]
mov [edi],eax ; Save to 'v3'
; Example 4 - base register + index register * scale factor
mov ebx,offset FibNumbers ; ebx = FibNumbers
mov esi,[ebp+8] ; esi = i
mov eax,[ebx+esi*4] ; Load table value
mov edi,[ebp+24]
nov [edi],eax ; Save to 'v4'
mov eax,1 ; Set return code
InvalidIndex:
pop edi
pop eso
pop ebx
pop ebp
ret
MemoryAddressing_ endp
end