Subscribe Us

header ads

Highlight Code 2

LINE NUMBERS
TITLE 'extern "C" int atoi_asm(const char *sz);'
.386P

.model FLAT

PUBLIC	_atoi_asm

_ALPHATOINT	SEGMENT
_atoi_asm	PROC NEAR


	mov  edx, DWORD PTR [esp+4] ; sz

label1:

; skip white space

	mov  al, BYTE PTR [edx]
	cmp  al, 32 ; ' '
	je   SHORT label2
	cmp  al, 9  ; '\t'
	je   SHORT label2
	cmp  al, 13 ; '\r'
	je   SHORT label2
	cmp  al, 10 ; '\n'
	jne  SHORT label3

label2:

	inc  edx
	jmp  SHORT label1
	
label3:

	xor  ecx, ecx
	mov  cl, BYTE PTR [edx]
	inc  edx
	push esi

	cmp  ecx, 45 ; '-'
	mov  esi, ecx
	je   SHORT label4
	cmp  ecx, 43 ; '+'
	jne  SHORT label5
	
label4:

	xor  ecx, ecx
	mov  cl, BYTE PTR [edx]
	inc  edx
	
label5:

	xor  eax, eax

	cmp  ecx, 48 ; '0'
	jl   SHORT label7
	
label6:

	cmp  ecx, 57 ; '9'
	jg   SHORT label7

	lea  eax, DWORD PTR [eax+eax*4]
	lea  eax, DWORD PTR [ecx+eax*2-48]

	xor  ecx, ecx
	mov  cl, BYTE PTR [edx]
	inc  edx
	cmp  ecx, 48 ; '0'
	jge  SHORT label6

label7:

	cmp  esi, 45 ; '-'
	pop  esi
	jne  SHORT label8
	neg  eax
	
label8:

	ret  0

_atoi_asm	ENDP
_ALPHATOINT	ENDS
END
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Document</title>
</head>
<body>
	
</body>
</html>

একটি মন্তব্য পোস্ট করুন

0 মন্তব্যসমূহ