This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
CAHomework/Homework 8/maggioni_rodolfo_masera_ca8_ex3.jas

51 lines
824 B
Text
Raw Normal View History

2018-11-26 16:20:14 +00:00
// product.jas
.constant
OBJREF 0x40 // needed for method invokation - see S.C.O. chapter 4
.end-constant
.main // start of program
LDC_W OBJREF // do not forget to push OBJREF on stack!
BIPUSH 0x15 // paramater n (i.e., n = 21)
2018-11-28 13:06:48 +00:00
BIPUSH 0x9 // paramater m (i.e., m = 9)
2018-11-26 16:20:14 +00:00
INVOKEVIRTUAL product
HALT // stops program execution
.end-main
.method product(n,m) // takes two arguments ("n" and "m")
.var
temp // change variable names as needed
.end-var
// just some code example:
BIPUSH 0x00
ISTORE temp
loop:
ILOAD m
IFEQ end
2018-11-28 13:06:48 +00:00
ILOAD temp
ILOAD n
ILOAD m
IFLT subsum
2018-11-26 16:20:14 +00:00
IADD
2018-11-28 13:06:48 +00:00
GOTO donesum
subsum:
ISUB
donesum:
2018-11-26 16:20:14 +00:00
ISTORE temp
ILOAD m
2018-11-28 13:06:48 +00:00
BIPUSH 1
ILOAD m
IFLT add
ISUB
GOTO update
add:
IADD
update:
2018-11-26 16:20:14 +00:00
ISTORE m
GOTO loop
end:
// this is obviously very useful
2018-11-28 13:06:48 +00:00
ILOAD temp
2018-11-26 16:20:14 +00:00
IRETURN
.end-method