-
Notifications
You must be signed in to change notification settings - Fork 23
menambahkan program simple atoi #13
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
base: main
Are you sure you want to change the base?
Changes from all commits
5916caf
a0cf87c
c26534c
13fce27
5e872a6
2d62ed6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| ;program untuk menconvert input dari user menjadi angka karena input yang di dapat | ||
| ;berupa karakter ascii bukan angka | ||
| ;atau program ini atoi pada bahasa c dengan versi saya sendiri | ||
| ;algoritmanya adalah kali sepuluh hasil yang ditampung terus ditambah dengan digit baru | ||
|
|
||
|
|
||
| section .data | ||
| num db 0 | ||
|
|
||
| section .text | ||
| global _start | ||
|
|
||
| _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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| mov ecx,num | ||
| mov edx,3 | ||
| int 0x80 | ||
|
Comment on lines
+15
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| mov edi,num | ||
|
|
||
| mov al, byte 0 ;hasil perkalian | ||
|
|
||
|
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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 | ||
|
Comment on lines
+26
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent spaces. |
||
|
|
||
| mul dl ;kali angka | ||
| add al,bl ;tambahkan hasil perkalian dengan digit input | ||
|
|
||
| inc edi ;char selanjutnya | ||
| jmp get_char | ||
|
Comment on lines
+25
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very wrong Simple test cases that prove this wrong: |
||
|
|
||
|
|
||
| ;hasil nya berada pada register eax tepatnya di al berukuran 1 byte | ||
| end: | ||
| mov eax,1 | ||
| mov ebx,0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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.
num db 0cuma allocate 1 byte saja, tapi di syscall readnya specify bufferlength 3 bytes. Overflow write to memory!!!
Kenapa tidak pakai uninitialized storage saja di
.bss?Misal:
dan juga kenapa cuma 3 karakter doang readnya?