Open
Conversation
slowy07
approved these changes
Jun 21, 2022
Member
slowy07
left a comment
There was a problem hiding this comment.
terima kasih atas kontribusinya, bisakah kamu amend commit messagenya dengan mengawali messagenya sesuai dengan CONTRIBUTING.md?
ammarfaizi2
reviewed
Jul 28, 2022
Comment on lines
+20
to
+22
|
|
||
| mov al, byte 0 ;hasil perkalian | ||
|
|
Comment on lines
+5
to
+7
| section .data | ||
| num db 0 | ||
|
|
There was a problem hiding this comment.
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 |
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 |
There was a problem hiding this comment.
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 |
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 |
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 |
There was a problem hiding this comment.
This is very wrong atoi().
Simple test cases that prove this wrong:
+-------+-------+
| Input | Hasil |
+-------+-------+
| 3333 | 773 |
| 4444 | 1884 |
| 5555 | 435 |
+-------+-------+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
menambahkan program ataoi atau procedure c dengan versi simple