.model tiny .code .startup Org 100h Jmp Short Start Vector Dw 2, 7, -1, 16, 15 N Equ 5 Start: Xor Bx, Bx Xor Si, Si Mov Cx, N S: Mov Ax, Vector[Bx] Add Bx, 2 Cmp Ax, 0 Jle _next Add Dx, Ax Inc Si _next: Loop S Idiv Si .exit 0 endBut I have real troubles figuring out the end of program, which calculates this average value. I would be very thankful if someone could help me with this, because it would help me to understand how this thing works, for now, i can't figure it out, i think i`m not good at this and probably wont be, because we have assembly only for first semester and it won't help me to understand it fully :/
3 replies to this topic
#1
Posted 10 December 2011 - 05:12 AM
Hello, i have a task, to create program which finds all negative values in vector and calculates average of all found negative values. So far i have done this:
|
|
|
#2
Posted 11 December 2011 - 05:09 PM
woohooXX said:
Jle _next
Don't you mean
j[COLOR=#FF0000][B]g[/B][/COLOR]e _next? I mean, you're only interested in values less than 0, you're not interested in omitting values that are less than 0, what you're doing in the code you posted.
As for the ending, you mean outputting the result?
#3
Posted 11 December 2011 - 10:06 PM
I rewrote my code in different way:
.model tiny .code .startup Org 100h Jmp Short Start Vector Dw 2, -7, -1, 16, -15 N Equ 5 Start: Xor Bx, Bx Xor Dx, Dx Xor Si, Si Mov Cx, N Dec Cx S: Mov Ax, Vector[Bx] Add Bx, 2 Cmp Ax, 0 Jge _next Inc Si Add Dx, Ax _next: Dec Cx Loop S AVG: Mov Ax, Dx Cwd Idiv Si .exit 0 endI need to save average values in Ax register and print them out, but when I check my results they are kinda wrong
#4
Posted 12 December 2011 - 02:10 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









