-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfind_string_lengh_2.asm
More file actions
51 lines (41 loc) · 1.23 KB
/
find_string_lengh_2.asm
File metadata and controls
51 lines (41 loc) · 1.23 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
; Find String Length Method 2
; author : surajsinghbisht054@gmail.com
;
; BSS Section
SECTION .bss
; Data Section
SECTION .data
string db "0123456789", 0AH ; Decleare String + 0AH is a New line ASCII HEXA code
; Text Section
SECTION .text
global _start
;
; Plan
; Iterate String From Starting to End, Until 0 bit found (End).
; Also Keep Record, The Number of times of iteration Routine.
; This Iteration Register will denote the length of string
;
; Routine Start
_start:
mov eax, string ; mov string starting point memory address to EAX
mov ebx, 0 ; SET EBX = 0
; Routine iterate
_iterate:
sub byte[eax], 0 ; Compare EAX first byte with 0, if equal set zero flag to 1 else set zero flag to 0
jz _gotit ; if Zerof flag is 1, Follow _gotit Routine, Else pass
inc eax ; Increase EAX
inc ebx ; keep record, Number of String Characters Checked
jmp _iterate ; Repeat
; Routine When, String End Found
_gotit:
mov edx, ebx ; set EDX = EBX [Length of String]
mov eax, 4 ; invoke SYS_Write
mov ebx, 1 ; STDOUT
mov ecx, string ; Move String Memory Address To ECX
int 80h ; kernel interpt
call _exit ; Follow Exit Routine
; Exit Routine
_exit:
mov eax, 1 ; Invoke SYS_EXIT
mov ebx, 0 ; Return Value
int 80h ; Kernel interpt