Skip to content

menambahkan program simple atoi#13

Open
Rino-Saputra wants to merge 6 commits into
bellshade:mainfrom
Rino-Saputra:main
Open

menambahkan program simple atoi#13
Rino-Saputra wants to merge 6 commits into
bellshade:mainfrom
Rino-Saputra:main

Conversation

@Rino-Saputra

Copy link
Copy Markdown
Contributor

menambahkan program ataoi atau procedure c dengan versi simple

@slowy07 slowy07 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terima kasih atas kontribusinya, bisakah kamu amend commit messagenya dengan mengawali messagenya sesuai dengan CONTRIBUTING.md?

@ammarfaizi2 ammarfaizi2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken.

Comment on lines +20 to +22

mov al, byte 0 ;hasil perkalian

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xor eax, eax?

Comment on lines +5 to +7
section .data
num db 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num db 0 cuma allocate 1 byte saja, tapi di syscall readnya specify buffer
length 3 bytes. Overflow write to memory!!!

Kenapa tidak pakai uninitialized storage saja di .bss?

Misal:

section .bss
	num resb 32

dan juga kenapa cuma 3 karakter doang readnya?

_start:
;code here
mov eax,3 ;sys_read
mov ebx,0 ;file desceiptor stdin

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xor ebx, ebx?

Comment on lines +13 to +17
mov eax,3 ;sys_read
mov ebx,0 ;file desceiptor stdin
mov ecx,num
mov edx,3
int 0x80

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read 3 bytes, kamu masukin angka 2 karakter, lalu enter itu sudah 3 bytes.
Gimana kalau inputnya lebih dari 2 karakter? Hmmm?

;hasil nya berada pada register eax tepatnya di al
end:
mov eax,1
mov ebx,0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xor ebx, ebx?

Comment on lines +24 to +35

movzx edx, byte[edi] ;mov one byte edi to edx / dl

cmp dl,48 ;jika kurang dari 0 end program
jl end

cmp dl,57 ;jika lebih dari 9 end program
jg end

mov bl,byte [edi]
sub bl, byte '0'
mov dl, byte 10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spaces.

Comment on lines +23 to +41
get_char:

movzx edx, byte[edi] ;mov one byte edi to edx / dl

cmp dl,48 ;jika kurang dari 0 end program
jl end

cmp dl,57 ;jika lebih dari 9 end program
jg end

mov bl,byte [edi]
sub bl, byte '0'
mov dl, byte 10

mul dl ;kali angka
add al,bl ;tambahkan hasil perkalian dengan digit input

inc edi ;char selanjutnya
jmp get_char

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very wrong atoi().

Simple test cases that prove this wrong:

+-------+-------+
| Input | Hasil |
+-------+-------+
| 3333  | 773   |
| 4444  | 1884  |
| 5555  | 435   |
+-------+-------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants