Jump to content

Assembly Task(TASM\Turbo Assembly)

- - - - -

  • Please log in to reply
3 replies to this topic

#1
woohooXX

woohooXX

    Newbie

  • Members
  • Pip
  • 2 posts
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:

.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

end

But 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 :/

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US

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
woohooXX

woohooXX

    Newbie

  • Members
  • Pip
  • 2 posts
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

end
I need to save average values in Ax register and print them out, but when I check my results they are kinda wrong

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Try getting rid of the dec cx right before the beginning of the loop.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users