This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.asm
63 lines (49 loc) · 2.14 KB
/
7.asm
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
bits 32 ; assembling for the 32 bits architecture
; declare the EntryPoint (a label defining the very first instruction of the program)
global start
; declare external functions needed by our program
extern exit ; tell nasm that exit exists even if we won't be defining it
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
; our data is declared here (the variables needed by our program)
segment data use32 class=data
S1 DB 1, 3, 5, 7 ; source 1
S2 DB 2, 6, 9, 4 ; source 2
S_Len EQU $-S2 ; same for S1 and S2
D RESB 2 * S_Len ; destiation
; Se dau doua siruri de octeti S1 si S2 de aceeasi lungime. Sa se obtina sirul D prin intercalarea elementelor celor doua siruri.
segment code use32 class=code
start:
; jmp start_loop ; change method to use
; start_arr:
; cld
; mov ESI, S1
; mov EBX, S_Len-1
; mov EDI, D
; mov ECX, S_Len
; .iterate:
; movsb
; add ESI, EBX
; movsb
; stc
; sbb ESI, EBX
; loop .iterate
; jmp terminate
; start_loop:
xor ESI, ESI ; ESI = 0
xor EDI, EDI ; EDI = 0
mov ECX, S_Len ; ECX = len(S1), prepare loop
jecxz terminate
.iterate:
mov AL, [S1+ESI] ; AL = S1[ESI]
mov [D+EDI], AL ; D[EDI] = AL
inc EDI ; EDI++
mov AL, [S2+ESI] ; AL = S2[ESI]
mov [D+EDI], AL ; D[EDI] = AL
inc EDI ; EDI ++
inc ESI ; ESI ++
loop .iterate
terminate:
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program