Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

menambahkan program simple atoi #13

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Rino-Saputra
Copy link
Contributor

menambahkan program ataoi atau procedure c dengan versi simple

Copy link
Member

@slowy07 slowy07 left a comment

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?

Copy link

@ammarfaizi2 ammarfaizi2 left a comment

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

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

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

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

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

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

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

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