done stuff

This commit is contained in:
Tommaso Rodolfo Masera 2018-11-28 14:06:48 +01:00
parent 9f9dbb4807
commit 2d86c87c0f
3 changed files with 30 additions and 5 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@ OBJREF 0x40 // needed for method invokation - see S.C.O. chapter 4
.main // start of program .main // start of program
LDC_W OBJREF // do not forget to push OBJREF on stack! LDC_W OBJREF // do not forget to push OBJREF on stack!
BIPUSH 0x15 // paramater n (i.e., n = 21) BIPUSH 0x15 // paramater n (i.e., n = 21)
BIPUSH 0x09 // paramater m (i.e., m = 9) BIPUSH 0x9 // paramater m (i.e., m = 9)
INVOKEVIRTUAL product INVOKEVIRTUAL product
HALT // stops program execution HALT // stops program execution
.end-main .end-main
@ -22,16 +22,29 @@ temp // change variable names as needed
loop: loop:
ILOAD m ILOAD m
IFEQ end IFEQ end
ILOAD n ILOAD temp
ILOAD temp ILOAD n
ILOAD m
IFLT subsum
IADD IADD
GOTO donesum
subsum:
ISUB
donesum:
ISTORE temp ISTORE temp
BIPUSH 0xFF
ILOAD m ILOAD m
ISUB BIPUSH 1
ILOAD m
IFLT add
ISUB
GOTO update
add:
IADD
update:
ISTORE m ISTORE m
GOTO loop GOTO loop
end: end:
// this is obviously very useful // this is obviously very useful
ILOAD temp
IRETURN IRETURN
.end-method .end-method

12
Homework 8/ex3.py Normal file
View File

@ -0,0 +1,12 @@
def product(n,m):
temp = 0
while m != 0:
if m > 0:
temp = temp + n
else:
temp = temp - n
if m > 0:
m = m - 1
else:
m = m + 1
return temp