flat assembler
Message board for the users of flat assembler.
Index
> Windows > run error |
Author |
|
rkatsiri 09 Feb 2016, 12:46
Hi, I get a run error when i try running this program.
Is there a wrong command or a logic error in this code? I'm new to assembly, so sorry if my question seems dum... I wrote it in attempt to do this: Write a program that takes the number n as input. Then it prints all the numbers x below n that have exactly 2 different integral divisors (Besides 1 and x). Here's the code i wrote: Code: start: call read_hex ; eax <- n cmp eax,6h jb exit_program ;(if n is below 6, which is the smallest number with only 2 divisors) mov esi,2h ; esi <- 2 dec eax ; x <- n-- (x is the biggest number below n) check_integers: mov ebx, eax ;ebx <- x mov edi, 0h ; 0 divisiors div esi ; eax <- x/2 , edx <- remainder call print_eax ; print just to check the code mov ecx, eax ; ecx <- x/2 mov eax, ebx ; eax <- x count_divisors: div ecx ; eax <- x / (x/2) , edx <- remainder mov eax, ebx ; eax <- x cmp edx, 0h jnz skip_inc_divisors ;(if remainder not equal 0) inc edi ; divisiors++ skip_inc_divisors: dec ecx ; ecx-- cmp ecx, 2h jnb count_divisors ;(if ecx not below 2) cmp edi, 2h; jne skip_print call print_eax ; print x (print x if equals 2) skip_print: dec eax ; x-- cmp eax,6h jnb check_integers ;(if eax not below 6, which is the smallest number with only 2 divisors) exit_program: ; Exit the process: push 0 call [ExitProcess] include 'training.inc'
|
|||||||||||
09 Feb 2016, 12:46 |
|
rkatsiri 09 Feb 2016, 19:01
AsmGuru62, I've just added the following line in the beginning of the code:
Code: mov edx, 0h But unfortunately, i still get a run error, right after the following output: 3 55555557[/code][/b] |
|||
09 Feb 2016, 19:01 |
|
AsmGuru62 10 Feb 2016, 04:34
Once DIV is complete - EDX may be set to a remainder - may be not zero.
So, you need to reset it to 0 before every DIV - you have another DIV below in the code. Let me check the code in debugger. Update: I added two lines (marked with AG62) and code seems to run OK: Code: ... check_integers: mov ebx, eax ;ebx <- x mov edi, 0h ; 0 divisiors mov edx, 0h ; AG62 - need EDX = 0 before DIV div esi ; eax <- x/2 , edx <- remainder call print_eax ; print just to check the code mov ecx, eax ; ecx <- x/2 mov eax, ebx ; eax <- x count_divisors: mov edx, 0h ; AG62 - need EDX = 0 before DIV div ecx ; eax <- x / (x/2) , edx <- remainder mov eax, ebx ; eax <- x cmp edx, 0h jnz skip_inc_divisors ;(if remainder not equal 0) inc edi ; divisiors++ ... |
|||
10 Feb 2016, 04:34 |
|
Mikl___ 10 Feb 2016, 06:00
Code: mov edx,eax ; AG62 - need EDX = 0 before DIV and edx,1 ; edx <- remainder shr eax,1 ; eax <- x/2 call print_eax ; print just to check the code |
|||
10 Feb 2016, 06:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.