addsub.c
1 /* 2 * Bean Java VM 3 * Copyright (C) 2005-2015 Christian Lins <christian@lins.me> 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #include <stdlib.h> 19 20 #include <debug.h> 21 #include <stack.h> 22 #include <stackframe.h> 23 #include <thread.h> 24 25 void do_IADD(Thread* thread) 26 { 27 dbgmsg("IADD"); 28 int *value1; 29 int *value2; 30 Stackframe* frame = current_frame(thread); 31 32 /* Retrieving values from operand stack */ 33 Stack_pop(&(frame->operandStack), (void **) &value2); 34 value1 = (int *) frame->operandStack.top->data; 35 36 /* Subtracting */ 37 *value1 = (*value1) + (*value2); 38 39 /* As we're modifying the stack top directly, we do not need to push 40 * the result back. But we should free value2. */ 41 free(value2); 42 } 43 44 void do_LADD(Thread* thread) 45 { 46 dbgmsg("LADD"); 47 int64_t *value1; 48 int64_t *value2; 49 Stackframe* frame = current_frame(thread); 50 51 /* Retrieving values from operand stack */ 52 Stack_pop(&(frame->operandStack), (void **) &value2); 53 value1 = (int64_t *) frame->operandStack.top->data; 54 55 /* Subtracting */ 56 *value1 = (*value1) + (*value2); 57 58 /* As we're modifying the stack top directly, we do not need to push 59 * the result back. But we should free value2. */ 60 free(value2); 61 } 62 63 void do_FADD(Thread* thread) 64 { 65 dbgmsg("FADD"); 66 float *value1; 67 float *value2; 68 Stackframe* frame = current_frame(thread); 69 70 /* Retrieving values from operand stack */ 71 Stack_pop(&(frame->operandStack), (void **) &value2); 72 value1 = (float *) frame->operandStack.top->data; 73 74 /* Subtracting */ 75 *value1 = (*value1) + (*value2); 76 77 /* As we're modifying the stack top directly, we do not need to push 78 * the result back. But we should free value2. */ 79 free(value2); 80 } 81 82 void do_DADD(Thread* thread) 83 { 84 dbgmsg("DADD"); 85 double *value1; 86 double *value2; 87 Stackframe* frame = current_frame(thread); 88 89 /* Retrieving values from operand stack */ 90 Stack_pop(&(frame->operandStack), (void **) &value2); 91 value1 = (double *) frame->operandStack.top->data; 92 93 /* Subtracting */ 94 *value1 = (*value1) + (*value2); 95 96 /* As we're modifying the stack top directly, we do not need to push 97 * the result back. But we should free value2. */ 98 free(value2); 99 } 100 101 void do_ISUB(Thread* thread) 102 { 103 dbgmsg("ISUB"); 104 105 int *value1; 106 int *value2; 107 Stackframe* frame = current_frame(thread); 108 109 /* Retrieving values from operand stack */ 110 Stack_pop(&(frame->operandStack), (void **) &value2); 111 value1 = (int *) frame->operandStack.top->data; 112 113 /* Subtracting */ 114 *value1 = (*value1) - (*value2); 115 116 /* As we're modifying the stack top directly, we do not need to push 117 * the result back. But we should free value2. */ 118 free(value2); 119 } 120 121 void do_LSUB(Thread* thread) 122 { 123 dbgmsg("LSUB"); 124 125 int64_t *value1; 126 int64_t *value2; 127 Stackframe* frame = current_frame(thread); 128 129 /* Retrieving values from operand stack */ 130 Stack_pop(&(frame->operandStack), (void **) &value2); 131 value1 = (int64_t *) frame->operandStack.top->data; 132 133 /* Subtracting */ 134 *value1 = (*value1) - (*value2); 135 136 /* As we're modifying the stack top directly, we do not need to push 137 * the result back. But we should free value2. */ 138 free(value2); 139 } 140 141 void do_FSUB(Thread* thread) 142 { 143 dbgmsg("FSUB"); 144 145 float *value1; 146 float *value2; 147 Stackframe* frame = current_frame(thread); 148 149 /* Retrieving values from operand stack */ 150 Stack_pop(&(frame->operandStack), (void **) &value2); 151 value1 = (float *) frame->operandStack.top->data; 152 153 /* Subtracting */ 154 *value1 = (*value1) - (*value2); 155 156 /* As we're modifying the stack top directly, we do not need to push 157 * the result back. But we should free value2. */ 158 free(value2); 159 } 160 161 void do_DSUB(Thread* thread) 162 { 163 dbgmsg("DSUB"); 164 165 double *value1; 166 double *value2; 167 Stackframe* frame = current_frame(thread); 168 169 /* Retrieving values from operand stack */ 170 Stack_pop(&(frame->operandStack), (void **) &value2); 171 value1 = (double *) frame->operandStack.top->data; 172 173 /* Subtracting */ 174 *value1 = (*value1) - (*value2); 175 176 /* As we're modifying the stack top directly, we do not need to push 177 * the result back. But we should free value2. */ 178 free(value2); 179 }