Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,4 +1,5 @@
|
|||
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function.
|
||||
A function is a body of code that returns a value.
|
||||
The value returned may depend on arguments provided to the function.
|
||||
|
||||
Write a definition of a function called "multiply" that takes two arguments and returns their product.
|
||||
(Argument types should be chosen so as not to distract from showing how functions are created and values returned).
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Functions and subroutines
|
||||
- Simple
|
||||
note: Basic language learning
|
||||
|
|
|
|||
4
Task/Function-definition/Eiffel/function-definition.e
Normal file
4
Task/Function-definition/Eiffel/function-definition.e
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
multiply(a, b: INTEGER): INTEGER
|
||||
do
|
||||
Result := a*b
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(defun multiply (x y)
|
||||
(* x y))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(defun multiply (x y)
|
||||
"Return the product of X and Y."
|
||||
(* x y))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
multiply(x,y) = x*y
|
||||
|
||||
# then for example
|
||||
print multiply(123,456)
|
||||
3
Task/Function-definition/OOC/function-definition.ooc
Normal file
3
Task/Function-definition/OOC/function-definition.ooc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
multiply: func (a: Double, b: Double) -> Double {
|
||||
a * b
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use signatures;
|
||||
use experimental 'signatures';
|
||||
sub multiply ($x, $y) {
|
||||
return $x * $y;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
Function Multiply(a As Integer, b As Integer) As Integer
|
||||
Return a * b
|
||||
End Function
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
@(do (defun mult (a b) (* a b))
|
||||
(format t "3 * 4 = ~a\n" (* 3 4)))
|
||||
(put-line `3 * 4 = @(mult 3 4)`))
|
||||
|
|
|
|||
|
|
@ -1,24 +1,7 @@
|
|||
section .text
|
||||
global _start
|
||||
|
||||
_multiply_regs:
|
||||
mul ebx
|
||||
mov eax, ebx
|
||||
ret
|
||||
|
||||
_multiply_stack:
|
||||
enter 2,0
|
||||
mov eax, [esp+4]
|
||||
mov ebx, [esp+8]
|
||||
mul ebx
|
||||
mov eax, ebx
|
||||
leave
|
||||
ret
|
||||
|
||||
_start:
|
||||
mov ax, 6 ;The number to multiply by
|
||||
mov ebx, 16 ;base number to multiply.
|
||||
call _multiply_regs
|
||||
push 6
|
||||
push 16
|
||||
call _multiply_stack
|
||||
.text
|
||||
.globl multiply
|
||||
.type multiply,@function
|
||||
multiply:
|
||||
movl 4(%esp), %eax
|
||||
mull 8(%esp)
|
||||
ret
|
||||
|
|
|
|||
|
|
@ -1,7 +1,24 @@
|
|||
multiply proc arg1:dword, arg2:dword
|
||||
mov eax, arg1
|
||||
mov ebx, arg2
|
||||
section .text
|
||||
global _start
|
||||
|
||||
_multiply_regs:
|
||||
mul ebx
|
||||
mov eax, ebx
|
||||
ret
|
||||
multiply endp
|
||||
|
||||
_multiply_stack:
|
||||
enter 2,0
|
||||
mov eax, [esp+4]
|
||||
mov ebx, [esp+8]
|
||||
mul ebx
|
||||
mov eax, ebx
|
||||
leave
|
||||
ret
|
||||
|
||||
_start:
|
||||
mov ax, 6 ;The number to multiply by
|
||||
mov ebx, 16 ;base number to multiply.
|
||||
call _multiply_regs
|
||||
push 6
|
||||
push 16
|
||||
call _multiply_stack
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
invoke multiply, 6, 16
|
||||
;or..
|
||||
push 16
|
||||
push 6
|
||||
call multiply
|
||||
multiply proc arg1:dword, arg2:dword
|
||||
mov eax, arg1
|
||||
mov ebx, arg2
|
||||
mul ebx
|
||||
mov eax, ebx
|
||||
ret
|
||||
multiply endp
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
invoke multiply, 6, 16
|
||||
;or..
|
||||
push 16
|
||||
push 6
|
||||
call multiply
|
||||
Loading…
Add table
Add a link
Reference in a new issue