September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -22,4 +22,6 @@ Print the value (with a newline) and divide it by two each time through the loop
|
|||
* [[Loops/N plus one half]]
|
||||
* [[Loops/Nested]]
|
||||
* [[Loops/While]]
|
||||
* [[Loops/with multiple ranges]]
|
||||
* [[Loops/Wrong ranges]]
|
||||
<br><br>
|
||||
|
|
|
|||
118
Task/Loops-While/ARM-Assembly/loops-while.arm
Normal file
118
Task/Loops-While/ARM-Assembly/loops-while.arm
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program loopwhile.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessResult: .ascii "" @ message result
|
||||
sMessValeur: .fill 11, 1, ' '
|
||||
szCarriageReturn: .asciz "\n"
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: @ entry of program
|
||||
mov r4,#1024 @ loop counter
|
||||
1: @ begin loop
|
||||
mov r0,r4
|
||||
ldr r1,iAdrsMessValeur @ display value
|
||||
bl conversion10 @ decimal conversion
|
||||
ldr r0,iAdrszMessResult
|
||||
bl affichageMess @ display message
|
||||
ldr r0,iAdrszCarriageReturn
|
||||
bl affichageMess @ display return line
|
||||
lsr r4,#1 @ division by 2
|
||||
cmp r4,#0 @ end ?
|
||||
bgt 1b @ no ->begin loop one
|
||||
|
||||
|
||||
100: @ standard end of the program
|
||||
mov r0, #0 @ return code
|
||||
mov r7, #EXIT @ request to exit program
|
||||
svc #0 @ perform the system call
|
||||
|
||||
iAdrsMessValeur: .int sMessValeur
|
||||
iAdrszMessResult: .int szMessResult
|
||||
iAdrszCarriageReturn: .int szCarriageReturn
|
||||
/******************************************************************/
|
||||
/* display text with size calculation */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the message */
|
||||
affichageMess:
|
||||
push {r0,r1,r2,r7,lr} @ save registres
|
||||
mov r2,#0 @ counter length
|
||||
1: @ loop length calculation
|
||||
ldrb r1,[r0,r2] @ read octet start position + index
|
||||
cmp r1,#0 @ if 0 its over
|
||||
addne r2,r2,#1 @ else add 1 in the length
|
||||
bne 1b @ and loop
|
||||
@ so here r2 contains the length of the message
|
||||
mov r1,r0 @ address message in r1
|
||||
mov r0,#STDOUT @ code to write to the standard output Linux
|
||||
mov r7, #WRITE @ code call system "write"
|
||||
svc #0 @ call systeme
|
||||
pop {r0,r1,r2,r7,lr} @ restaur registers */
|
||||
bx lr @ return
|
||||
/******************************************************************/
|
||||
/* Converting a register to a decimal */
|
||||
/******************************************************************/
|
||||
/* r0 contains value and r1 address area */
|
||||
.equ LGZONECAL, 10
|
||||
conversion10:
|
||||
push {r1-r4,lr} @ save registers
|
||||
mov r3,r1
|
||||
mov r2,#LGZONECAL
|
||||
1: @ start loop
|
||||
bl divisionpar10 @ r0 <- dividende. quotient ->r0 reste -> r1
|
||||
add r1,#48 @ digit
|
||||
strb r1,[r3,r2] @ store digit on area
|
||||
cmp r0,#0 @ stop if quotient = 0
|
||||
subne r2,#1 @ previous position
|
||||
bne 1b @ else loop
|
||||
@ end replaces digit in front of area
|
||||
mov r4,#0
|
||||
2:
|
||||
ldrb r1,[r3,r2]
|
||||
strb r1,[r3,r4] @ store in area begin
|
||||
add r4,#1
|
||||
add r2,#1 @ previous position
|
||||
cmp r2,#LGZONECAL @ end
|
||||
ble 2b @ loop
|
||||
mov r1,#0 @ final zero
|
||||
strb r1,[r3,r4]
|
||||
100:
|
||||
pop {r1-r4,lr} @ restaur registres
|
||||
bx lr @return
|
||||
/***************************************************/
|
||||
/* division par 10 signé */
|
||||
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
|
||||
/* and http://www.hackersdelight.org/ */
|
||||
/***************************************************/
|
||||
/* r0 dividende */
|
||||
/* r0 quotient */
|
||||
/* r1 remainder */
|
||||
divisionpar10:
|
||||
/* r0 contains the argument to be divided by 10 */
|
||||
push {r2-r4} @ save registers */
|
||||
mov r4,r0
|
||||
mov r3,#0x6667 @ r3 <- magic_number lower
|
||||
movt r3,#0x6666 @ r3 <- magic_number upper
|
||||
smull r1, r2, r3, r0 @ r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0)
|
||||
mov r2, r2, ASR #2 @ r2 <- r2 >> 2
|
||||
mov r1, r0, LSR #31 @ r1 <- r0 >> 31
|
||||
add r0, r2, r1 @ r0 <- r2 + r1
|
||||
add r2,r0,r0, lsl #2 @ r2 <- r0 * 5
|
||||
sub r1,r4,r2, lsl #1 @ r1 <- r4 - (r2 * 2) = r4 - (r0 * 10)
|
||||
pop {r2-r4}
|
||||
bx lr @ return
|
||||
5
Task/Loops-While/BASIC/loops-while-4.basic
Normal file
5
Task/Loops-While/BASIC/loops-while-4.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
i% = 1024
|
||||
WHILE i%
|
||||
PRINT i%
|
||||
i% DIV= 2
|
||||
ENDWHILE
|
||||
5
Task/Loops-While/BASIC/loops-while-5.basic
Normal file
5
Task/Loops-While/BASIC/loops-while-5.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
100 LET I=1024
|
||||
110 DO WHILE I>0
|
||||
120 PRINT I
|
||||
130 LET I=IP(I/2)
|
||||
140 LOOP
|
||||
8
Task/Loops-While/Cache-ObjectScript/loops-while.cos
Normal file
8
Task/Loops-While/Cache-ObjectScript/loops-while.cos
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
WHILELOOP
|
||||
set x = 1024
|
||||
while (x > 0) {
|
||||
write x,!
|
||||
set x = (x \ 2) ; using non-integer division will never get to 0
|
||||
}
|
||||
|
||||
quit
|
||||
|
|
@ -1,4 +1,14 @@
|
|||
(setq i 1024)
|
||||
(loop while (> i 0) do
|
||||
(print i)
|
||||
(setq i (floor i 2)))
|
||||
(let ((i 1024))
|
||||
(loop while (plusp i) do
|
||||
(print i)
|
||||
(setf i (floor i 2))))
|
||||
|
||||
(loop with i = 1024
|
||||
while (plusp i) do
|
||||
(print i)
|
||||
(setf i (floor i 2)))
|
||||
|
||||
(defparameter *i* 1024)
|
||||
(loop while (plusp *i*) do
|
||||
(print *i*)
|
||||
(setf *i* (floor *i* 2)))
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1024[p2/d0<p]dspx
|
||||
[ q ] sQ [ d 0!<Q p 2 / lW x ] sW 1024 lW x
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
program =
|
||||
[
|
||||
int i := 1024.
|
||||
public program()
|
||||
{
|
||||
int i := 1024;
|
||||
while (i > 0)
|
||||
[
|
||||
console writeLine:i.
|
||||
{
|
||||
console.writeLine:i;
|
||||
|
||||
i := i / 2.
|
||||
].
|
||||
].
|
||||
i /= 2
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
@tailrec
|
||||
def loop(iter: Int) {
|
||||
if ((iter > 0)) {
|
||||
if (iter > 0) {
|
||||
println(iter)
|
||||
loop(iter / 2)
|
||||
}
|
||||
|
|
|
|||
19
Task/Loops-While/Spin/loops-while.spin
Normal file
19
Task/Loops-While/Spin/loops-while.spin
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
con
|
||||
_clkmode = xtal1 + pll16x
|
||||
_clkfreq = 80_000_000
|
||||
|
||||
obj
|
||||
ser : "FullDuplexSerial.spin"
|
||||
|
||||
pub main | n
|
||||
ser.start(31, 30, 0, 115200)
|
||||
|
||||
n := 1024
|
||||
repeat while n > 0
|
||||
ser.dec(n)
|
||||
ser.tx(32)
|
||||
n /= 2
|
||||
|
||||
waitcnt(_clkfreq + cnt)
|
||||
ser.stop
|
||||
cogstop(0)
|
||||
8
Task/Loops-While/VBA/loops-while.vba
Normal file
8
Task/Loops-While/VBA/loops-while.vba
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Public Sub LoopsWhile()
|
||||
Dim value As Integer
|
||||
value = 1024
|
||||
Do While value > 0
|
||||
Debug.Print value
|
||||
value = value / 2
|
||||
Loop
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue