7 Replies - 387 Views - Last Post: 12 June 2017 - 08:40 PM

#1 Psrandh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 30-November 16

Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 06:23 PM

Hey guys, I'm having a lot of trouble with this assembly program. It's not due tomorrow, so I have some time, but I'd appreciate some help in understanding exactly how I am supposed to assemble this. I'm supposed to read integers in, keep a total of both the quantity and the sum of negative & positive integers once a zero is read in then:

* If there are more or equal positives and negatives a 0 is printed out and the sum of the positive integers.

* If there are more negatives than positives a 1 is printed out and the sum of the negative integers.

The first picture attached is what I have so far and the second picture is the instruction set we are supposed to work with. Just to be clear, I'd really appreciate it if someone could help me figure out how to finish this code, since one of my classmates told me I'm on the right track before bolting.

http://imgur.com/C1fPbky

http://imgur.com/0Dl3zZR

This post has been edited by Psrandh: 12 June 2017 - 06:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Really Confused With This Assembly Program - Reading Integers Until 0

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,843
  • Joined: 12-June 08

Re: Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 07:03 PM

Please copy/paste the code here as well as any error message and specific questions.
Was This Post Helpful? 0
  • +
  • -

#3 Psrandh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 30-November 16

Re: Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 07:05 PM

View Postmodi123_1, on 12 June 2017 - 07:03 PM, said:

Please copy/paste the code here as well as any error message and specific questions.


.begin
loop: in x
	load 0
	compare x
	jumpeq negative
	jumpgt positive
negative: increment minus
positive: increment plus
halt
x: .data 0
0: .data 0
plus: .data 0
minus: .data 0
.end



The thing is that I'm not getting any errors, I'm just not sure what I would do next given the instructions I have. I would really appreciate it if someone could help me.

This post has been edited by Psrandh: 12 June 2017 - 07:07 PM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,843
  • Joined: 12-June 08

Re: Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 07:18 PM

You haven't communicated what you are supposed to do next so I am at a loss there too.
Was This Post Helpful? 0
  • +
  • -

#5 Psrandh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 30-November 16

Re: Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 07:36 PM

View Postmodi123_1, on 12 June 2017 - 07:18 PM, said:

You haven't communicated what you are supposed to do next so I am at a loss there too.


I'm supposed to read integers in, which is why I have the loop and keep track of how many integers are read in. If there are more or the same amount of positive integers as negative then 0 is printed to screen and the sum of the positives. If there are more negatives than positives, then 1 is printed to the screen and the sum of the negatives.

So I created the loop with in x at the top so that numbers can be read in, there is compare x so that it can be checked if the number read in is positive or negative and depending on what it is, it jumps to positive or negative.

What I'm confused about is what do next. How would I keep track of how many numbers are printed in or out and then sum them up?
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,843
  • Joined: 12-June 08

Re: Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 07:58 PM

I would have a variable to increment each time a number is read, and have a second to add as a continuing sum.
Was This Post Helpful? 0
  • +
  • -

#7 Psrandh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 30-November 16

Re: Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 08:07 PM

View Postmodi123_1, on 12 June 2017 - 07:58 PM, said:

I would have a variable to increment each time a number is read, and have a second to add as a continuing sum.


I'm sorry, I'm a little confused by what you mean.

.begin
loop: in x
	load 0
	compare x
	jumpeq negative
	jumpgt positive
negative: increment minus
	out 1
positive: increment plus
	out 0
halt
x: .data 0
0: .data 0
1: .data 0
plus: .data 0
minus: .data 0
.end



I have increment minus to increase whenever a negative number is read and increment plus to increase whenever a positive number is read. But what do you mean for the variable add? Where exactly would I put that? In the loop or where?
Was This Post Helpful? 0
  • +
  • -

#8 Psrandh  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 30-November 16

Re: Really Confused With This Assembly Program - Reading Integers Until 0

Posted 12 June 2017 - 08:40 PM

View Postmodi123_1, on 12 June 2017 - 07:58 PM, said:

I would have a variable to increment each time a number is read, and have a second to add as a continuing sum.


Hey I think I'm getting close:

.begin
loop: in x
	load 0
	compare x
	jumpgt positive
	jumplt negative
positive: load plus
	increment plus
	load 1
	out 1
negative: load minus
	increment minus
	load 0
	out 0
halt
out i
x: .data 0
i: .data 0
0: .data 0
1: .data 1
plus: .data 0
minus: .data 0
.end



I'm still not sure on how to get the sum though.

This post has been edited by Psrandh: 12 June 2017 - 08:45 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1