done stuff
This commit is contained in:
parent
9f9dbb4807
commit
2d86c87c0f
3 changed files with 30 additions and 5 deletions
Binary file not shown.
|
@ -6,7 +6,7 @@ OBJREF 0x40 // needed for method invokation - see S.C.O. chapter 4
|
|||
.main // start of program
|
||||
LDC_W OBJREF // do not forget to push OBJREF on stack!
|
||||
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
|
||||
HALT // stops program execution
|
||||
.end-main
|
||||
|
@ -22,16 +22,29 @@ temp // change variable names as needed
|
|||
loop:
|
||||
ILOAD m
|
||||
IFEQ end
|
||||
ILOAD n
|
||||
ILOAD temp
|
||||
ILOAD temp
|
||||
ILOAD n
|
||||
ILOAD m
|
||||
IFLT subsum
|
||||
IADD
|
||||
GOTO donesum
|
||||
subsum:
|
||||
ISUB
|
||||
donesum:
|
||||
ISTORE temp
|
||||
BIPUSH 0xFF
|
||||
ILOAD m
|
||||
ISUB
|
||||
BIPUSH 1
|
||||
ILOAD m
|
||||
IFLT add
|
||||
ISUB
|
||||
GOTO update
|
||||
add:
|
||||
IADD
|
||||
update:
|
||||
ISTORE m
|
||||
GOTO loop
|
||||
end:
|
||||
// this is obviously very useful
|
||||
ILOAD temp
|
||||
IRETURN
|
||||
.end-method
|
||||
|
|
12
Homework 8/ex3.py
Normal file
12
Homework 8/ex3.py
Normal 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
|
Reference in a new issue