4 Replies - 9815 Views - Last Post: 05 November 2008 - 10:20 AM Rate Topic: -----

#1 hammster32  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-November 08

Pep 8 assembly find the minimum of 3 numbers

Post icon  Posted 05 November 2008 - 04:11 AM

Write a program to find the minimium of three numbers read from the user.

Convert This code to Pep8 assembly language
#include 
using namespace std;
int min(int a, int b, int c) {
   if (a<b) {
	 if (a<c)
		 return a;
	  else
		return c;
	}
   else {
	 if (b<c)
		return b;
	 else
	   return c;
   }
}
void main() { 
   int x,y,z;
	cin>>x>>y>>z;
	cout<<"Min is "<<min(x,y,z);
}



~added code tags
jjsaw5

Is This A Good Question/Topic? 0
  • +

Replies To: Pep 8 assembly find the minimum of 3 numbers

#2 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,060
  • Joined: 04-January 08

Re: Pep 8 assembly find the minimum of 3 numbers

Posted 05 November 2008 - 09:39 AM

Do you have a question?
Was This Post Helpful? 0
  • +
  • -

#3 hammster32  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-November 08

Re: Pep 8 assembly find the minimum of 3 numbers

Posted 05 November 2008 - 09:46 AM

View Postjjsaw5, on 5 Nov, 2008 - 08:39 AM, said:

Do you have a question?


Yes i am trying to translate this c++ code into Pep/8 assembly code..

Here is what i have so far but it will not work right..
;
		 BR	  main
a:	   .BLOCK  2		 ;global variable
b:	   .BLOCK  2		 ;global variable
c:	   .BLOCK  2		 ;global variable
;
;******* void swap (int& r, int& s int& t)
r:	   .EQUATE 6		 ;formal parameter
s: 	.EQUATE 4		 ;formal parameter
t:	  .EQUATE 2		 ;formal parameter
temp:	.EQUATE 0		 ;local variable
swap:	SUBSP   2,i	   ;allocate local
		 LDA	 r,sf	  ;temp = r
		 STA	 temp,s
		 LDA	 s,sf	  ;r = s
		 STA	 r,sf
		 LDA	 temp,s	;s = temp
		 STA	 s,sf
if:	 LDA	 t,sf
		 RET2 
	 STA	t,sf			;deallocate local, pop retAddr
else:	RET6
;
;******* void order (int& x, int& y, int& z )
x:	   .EQUATE 4		 ;formal parameter
y:	   .EQUATE 2		 ;formal parameter
z:	   .EQUATE 0		 ;formal parameter
order:   LDA	 x,sf	  ;if (x > y)
		 CPA	 y,sf
	
		 BRLE	endIf
		 LDA	 x,s	   ;   push x
		 STA	 -2,s
		 LDA	 y,s	   ;   push y
		 STA	 -4,s
		 SUBSP   4,i	   ;   push params
		 CALL	swap	  ;   swap (x, y)
		 ADDSP   4,i	   ;   pop params
endIf:   RET0			  ;pop retAddr
		 
;
;******* main ()
main:	DECI	a,d	   ;cin >> a
		 DECI	b,d	   ;cin >> b
	 DECI	c,d	   ;cin >> c
		 LDA	 a,i	   ;push the address of a
		 STA	 -2,s
		 LDA	 b,i	   ;push the address of b
		 STA	 -4,s
	 LDA	 c,i	   ;push the address of c
		 STA	 -4,s
		 SUBSP   4,i	   ;push params
		 CALL	order	 ;order (a, b, c)
ra1:	 ADDSP   4,i	   ;pop params
		 
	STRO	msg2,d	;cout << "Minimum is: "
		   DECO	a,d	   ;	 << a
		 STOP
msg2:	.ASCII  "Min: \x00"
msg3:	.ASCII  ", \x00"
		 .END



~added code tags
-jjsaw5
Was This Post Helpful? 0
  • +
  • -

#4 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,060
  • Joined: 04-January 08

Re: Pep 8 assembly find the minimum of 3 numbers

Posted 05 November 2008 - 10:06 AM

Please make sure that you are using the code tags when posting code.



What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#5 hammster32  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-November 08

Re: Pep 8 assembly find the minimum of 3 numbers

Posted 05 November 2008 - 10:20 AM

View Posthammster32, on 5 Nov, 2008 - 08:46 AM, said:

View Postjjsaw5, on 5 Nov, 2008 - 08:39 AM, said:

Do you have a question?


Yes i am trying to translate this c++ code into Pep/8 assembly code..

Here is what i have so far but it will not work right..
;
		 BR	  main
a:	   .BLOCK  2		;global variable
b:	   .BLOCK  2		;global variable
c:	   .BLOCK  2		;global variable
;
;******* void swap (int& r, int& s int& t)
r:	   .EQUATE 6		;formal parameter
s: 	.EQUATE 4		;formal parameter
t:	  .EQUATE 2		;formal parameter
temp:	.EQUATE 0		;local variable
swap:	SUBSP   2,i	  ;allocate local
		 LDA	 r,sf	 ;temp = r
		 STA	 temp,s
		 LDA	 s,sf	 ;r = s
		 STA	 r,sf
		 LDA	 temp,s;s = temp
		 STA	 s,sf
if:	 LDA	 t,sf
		 RET2 
	 STA	t,sf		;deallocate local, pop retAddr
else:	RET6
;
;******* void order (int& x, int& y, int& z )
x:	   .EQUATE 4		;formal parameter
y:	   .EQUATE 2		;formal parameter
z:	   .EQUATE 0		;formal parameter
order:   LDA	 x,sf	 ;if (x > y)
		 CPA	 y,sf
	
		 BRLE	endIf
		 LDA	 x,s	  ;   push x
		 STA	 -2,s
		 LDA	 y,s	  ;   push y
		 STA	 -4,s
		 SUBSP   4,i	  ;   push params
		 CALL	swap	 ;   swap (x, y)
		 ADDSP   4,i	  ;   pop params
endIf:   RET0			 ;pop retAddr
		 
;
;******* main ()
main:	DECI	a,d	  ;cin >> a
		 DECI	b,d	  ;cin >> b
	 DECI	c,d	  ;cin >> c
		 LDA	 a,i	  ;push the address of a
		 STA	 -2,s
		 LDA	 b,i	  ;push the address of b
		 STA	 -4,s
	 LDA	 c,i	  ;push the address of c
		 STA	 -4,s
		 SUBSP   4,i	  ;push params
		 CALL	order	;order (a, b, c)
ra1:	 ADDSP   4,i	  ;pop params
		 
	STRO	msg2,d;cout << "Minimum is: "
		   DECO	a,d	  ;	 << a
		 STOP
msg2:	.ASCII  "Min: \x00"
msg3:	.ASCII  ", \x00"
		 .END



~added code tags
-jjsaw5

i cannot find the minimum of the three numbers to display.. the problem does run but i am lost on how to formulate my code from here to enter 3 numbers and have the output sceen display the minimum or lowest value number and i cannot find anything anywhere for help and no one knows anything on how to do this. pep/8 code examples are hard to find and i have searched everywhere for help... Any help would be appreciated...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1