-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9afbc12
commit bef7042
Showing
18 changed files
with
401 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
push 1 | ||
pint | ||
push 2 | ||
pint | ||
push 3 | ||
pint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
push 1 | ||
push 2 | ||
push 3 | ||
pall | ||
pop | ||
pall | ||
pop | ||
pall | ||
pop | ||
pall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
push 1 | ||
push 2 | ||
push 3 | ||
pall | ||
swap | ||
pall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
push 1 | ||
push 2 | ||
push 3 | ||
pall | ||
add | ||
pall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
push 1 | ||
push 2 | ||
push 3 | ||
push 4 | ||
push 0 | ||
push 110 | ||
push 0 | ||
push 108 | ||
push 111 | ||
push 111 | ||
push 104 | ||
push 99 | ||
push 83 | ||
pstr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
push 72 | ||
pchar | ||
push 100 | ||
pchar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
push 1 | ||
push 2 | ||
push 3 | ||
push 4 | ||
push 0 | ||
push 110 | ||
push 0 | ||
push 108 | ||
push 111 | ||
push 111 | ||
push 104 | ||
push 99 | ||
push 83 | ||
pstr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
push 1 | ||
push 2 | ||
push 3 | ||
push 4 | ||
push 5 | ||
push 6 | ||
push 7 | ||
push 8 | ||
push 9 | ||
push 0 | ||
pall | ||
rotl | ||
# pint | ||
# pall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
push 11 | ||
push 3 | ||
add | ||
pall | ||
pop | ||
# pop | ||
# push 1 | ||
# mod | ||
# pall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include "monty.h" | ||
|
||
/** | ||
* _mul - multiplies first and second element in stack. | ||
* @stack_ptr: pointer to dlinkedlist | ||
* @count: line number | ||
*/ | ||
void _mul(stack_t **stack_ptr, unsigned int count) | ||
{ | ||
int num1, num2, result; | ||
|
||
if ((*stack_ptr) == NULL || (*stack_ptr)->next == NULL) | ||
{ | ||
printf("L%d: can't swap, stack too short", count); | ||
exit(EXIT_FAILURE); | ||
} | ||
num1 = (*stack_ptr)->n; | ||
num2 = (*stack_ptr)->next->n; | ||
result = num2 * num1; | ||
(*stack_ptr)->next->n = result; | ||
pop(stack_ptr, count); | ||
} | ||
|
||
/** | ||
* _mod - finds modulus of first and second element | ||
* @stack_ptr: pointer to dlinkedlist | ||
* @count: line number | ||
*/ | ||
void _mod(stack_t **stack_ptr, unsigned int count) | ||
{ | ||
int num1, num2, result; | ||
stack_t *tmp; | ||
tmp = *stack_ptr; | ||
|
||
if (tmp->next == NULL) | ||
{ | ||
printf("L%d: can't mod, stack too short", count); | ||
exit(EXIT_FAILURE); | ||
} | ||
num1 = tmp->n; | ||
num2 = tmp->next->n; | ||
result = num2 % num1; | ||
(*stack_ptr)->next->n = result; | ||
pop(stack_ptr, count); | ||
} | ||
|
||
/** | ||
* _add - adds first and second element in stack | ||
* @stack_ptr: pointer to dlinkedlist | ||
* @count: line number | ||
*/ | ||
void _add(stack_t **stack_ptr, unsigned int count) | ||
{ | ||
int num1, num2, result; | ||
|
||
if ((*stack_ptr) == NULL || (*stack_ptr)->next == NULL) | ||
{ | ||
printf("L%d: can't swap, stack too short", count); | ||
exit(EXIT_FAILURE); | ||
} | ||
num1 = (*stack_ptr)->n; | ||
num2 = (*stack_ptr)->next->n; | ||
result = num1 + num2; | ||
(*stack_ptr)->next->n = result; | ||
pop(stack_ptr, count); | ||
} | ||
/** | ||
* _div - divides second and first element in stack | ||
* @stack_ptr: pointer to dlinkedlist | ||
* @count: line number | ||
*/ | ||
void _div(stack_t **stack_ptr, unsigned int count) | ||
{ | ||
int num1, num2, result; | ||
|
||
if ((*stack_ptr) == NULL || (*stack_ptr)->next == NULL) | ||
{ | ||
printf("L%d: can't swap, stack too short", count); | ||
exit(EXIT_FAILURE); | ||
} | ||
num1 = (*stack_ptr)->n; | ||
num2 = (*stack_ptr)->next->n; | ||
result = num2 / num1; | ||
(*stack_ptr)->next->n = result; | ||
pop(stack_ptr, count); | ||
} | ||
/** | ||
* _sub -finds the difference first and second element in stack | ||
* @stack_ptr: pointer to dlinkedlist | ||
* @count: line number | ||
*/ | ||
|
||
void _sub(stack_t **stack_ptr, unsigned int count) | ||
{ | ||
int num1, num2, result; | ||
|
||
if ((*stack_ptr) == NULL || (*stack_ptr)->next == NULL) | ||
{ | ||
printf("L%d: can't swap, stack too short", count); | ||
exit(EXIT_FAILURE); | ||
} | ||
num1 = (*stack_ptr)->n; | ||
num2 = (*stack_ptr)->next->n; | ||
result = num2 - num1; | ||
(*stack_ptr)->next->n = result; | ||
pop(stack_ptr, count); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.