-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken.
|
||
mov al, byte 0 ;hasil perkalian | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xor eax, eax
?
section .data | ||
num db 0 | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xor ebx, ebx
?
mov eax,3 ;sys_read | ||
mov ebx,0 ;file desceiptor stdin | ||
mov ecx,num | ||
mov edx,3 | ||
int 0x80 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xor ebx, ebx
?
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spaces.
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 |
There was a problem hiding this comment.
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 |
+-------+-------+
menambahkan program ataoi atau procedure c dengan versi simple