Tuesday 15 March 2011

Infinite Loop x86 Assembly -


So I'm trying to create a program that imitates the collate sequence using the given phonemic code Which prints 5 numbers per line. I have been able to write the code in the x86 assembly code, but when I am compiling and running, I am not getting the desired results. Instead, I have been asked for input (which is correct), I get the infinite loop of 252 521. I do not understand why I feel like the way I am, it is for everyone n (integer) proc; However, I have never coded it because I am new enough for the assembly. I'm using TASM on a 64 bit win8 (if it helps).

I have 2 .asm files that are linked together, calculates Ulamatt and Ulllam, Ulamat and displays the results, while Uhmatus gets the value from the user and sends it to Ulam. Getint and putint are ASM files that allow easy input / output output and there is no problem (since I have not given them the code, they are from my professor).

Besides, I think how it might be that I change the CNT to count, I think I might have done something wrong in Ulam, but, as I said, I Not sure

Ulamtst:

  Title Ulam Test. Collatz sequence calculates a_ (n + 1) = a_n div 2, if a_n mod is 2 = 0 = 3 * a_n + 1, otherwise. Model small. Stack 100 H. Does data const.inc n dw include? Nl db cr, lf, '$' getN db 'n? $ '.code extrn getint: proc, ulam: proc main proc; Start of DS MOP ax, @ DATA mov DS, ax loop 01:; Write 'n? '; Mov ah, dispstr mov dx, offset getN int dosfunc; Read N; Call getint mov n, ax; Exit when n & lt; = 0 cmp n, 0 jle endloop01; Ulcom (n) mov ax, n call ulam mov n, ax; Write CR, LF MOV DX, Offset NL MH AH, Ribral Int. Doschmank JMP Loop 01 Endowup 01:; Returns - In DOS Mix Ah, ret2dos int dosfunc main endp end main  

Ulalaam:

  title ulam.asm; Collatz sequence calculates a_ (n + 1) = a_n div 2, if a_n mod is 2 = 0 = 3 * a_n + 1, otherwise. Model small. Stack 100 H. Does data const.inc n dw include? Nl db cr, lf, '$' showCount db cr, lf, 'length: $' .code extrn putint: proc public ulam proc; (N); A_ (n + 1) = a_n div 2, if a_n mod is 2 = 0 = 3 * a_n + 1, otherwise; Input: Ax = N; Output: None; Save the Ridge Push Ax; Ax = N push cx; Assigned to the count; Write CR, LF, N; Mov dx, offset nl mov ah, wrtr int dosfunc call putint; Count: = 0 x cx, cx repetition:; If02 count mod 5 = 0 mov n, ax mill, 5 IDE cx CMP dx, 0 JNA and INF 022; Then 02; Write CR, LF MOV DX, Offset NL MH AH, Ribble Int Doscopp Andif 02:; Calculation: = count + 1; Inc. cx; If03 n mod 2 = 0 mov ax, 2 moving n cmp dx, 0 jna other 0; Again ; N: = n div 2 mov ax, n mov bx, 2 idiv bx mov n, ax jmp endif03 else03:; N: = n * 3 + 1 mov ax, 3 imul n plus ax, 1 mov n, ax endif03:; Write '', n mov dl, '' mov ah, wrchr int dosfunc mov ax, n call putint; Until n = 1; CMP N, 1GN repetition; Andrépiet 01; Write CR, LF, 'Length:', Count; Mov ah, dispstr mov dx, offset showcount int dosfunc mov ax, cx call putint mov ax, n; Restore Registers Cx Pop AX Pop; Return writ; Returns - For DOS mov AH, ret2dos int dosfunc ulam endp end ulam  

This is the result when I enter 1 for n, and change slightly a bit of code, now I get this _ Continuous Blurring Enter image details here


No comments:

Post a Comment