# Pep 8 assembly find the minimum of 3 numbers

Page 1 of 1

## 4 Replies - 12743 Views - Last Post: 05 November 2008 - 10:20 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=70559&amp;s=a2b61e0ce77ee1c556730b8bcdd915f5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hammster32

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

# Pep 8 assembly find the minimum of 3 numbers

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);
}
```

jjsaw5

Is This A Good Question/Topic? 0

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

### #2 jjsaw5

• D.I.C Lover

Reputation: 92
• Posts: 3,063
• 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?

### #3 hammster32

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

## Re: Pep 8 assembly find the minimum of 3 numbers

Posted 05 November 2008 - 09:46 AM

jjsaw5, 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)

;
;******* 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)

STRO	msg2,d	;cout << "Minimum is: "
DECO	a,d	   ;	 << a
STOP
msg2:	.ASCII  "Min: \x00"
msg3:	.ASCII  ", \x00"
.END
```

-jjsaw5

### #4 jjsaw5

• D.I.C Lover

Reputation: 92
• Posts: 3,063
• 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?

### #5 hammster32

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

## Re: Pep 8 assembly find the minimum of 3 numbers

Posted 05 November 2008 - 10:20 AM

hammster32, on 5 Nov, 2008 - 08:46 AM, said:

jjsaw5, 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)

;
;******* 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)

STRO	msg2,d;cout << "Minimum is: "
DECO	a,d	  ;	 << a
STOP
msg2:	.ASCII  "Min: \x00"
msg3:	.ASCII  ", \x00"
.END
```