This commit is contained in:
Debucquoy
2023-09-20 15:18:20 +02:00
parent 00d0cdfaf3
commit 4fd7542f03
228 changed files with 351 additions and 12 deletions

View File

@ -0,0 +1,29 @@
#!/bin/python
def toBinaryString(user_i:int):
squares = [2**i for i in range(32)]
squares.reverse()
ret = ''
show = False
for s in squares:
if user_i & s:
ret += '1'
show=True
else:
if show:
ret += '0'
return ret
def main():
"""
Ask the user for an input
"""
user_in = input("entrez un nombre :")
print(toBinaryString(int(user_in)))
if __name__ == "__main__":
main()

View File

@ -0,0 +1,85 @@
# Exercices
## Binary
1) \\( \\)
2) 4095
3) 100000 (2) = 32 (10)
4) 000010 (2) = 2 (10)
5) 111111 (2) = 63 (10)
6) 010101 (2) = 21 (10)
7) 64 (10) = 0100 0000 (2)
8) 7 (10) = 0000 0100 (2)
9) 192 (10) = 1100 0000 (2)
10) 3073 (10) = 0110 0000 0001 (2)
11) 0x1010 = 4112
12) 0x10A0 = 4256
13) 0xBABE = 47806
14) 020 = 16
15) 072 = 58
16) sur papier = 0xCAFE
17) sur papier = 02001
18) 0xCAFE = 1100 1010 1111 1110
19) 0xCAFE = 0145376
20) 072 = 111010
21) > ./algo_q21.py
## Complement a 2
22)
23) \\( -2^11 → 2^11-1 \\)
24) 17 = 0001 0001
25) -17 = 1110 1101
26) 255 = 1111 1111 (Imposible car pas dans l'interval)
27) -128 = 1000 0000
28) -73 = 10110111
29) 01001111
+ 00000001
= 01010000
30) - 10010110 = 01101010
31) 01001111
+ 01000001
---------
= 10010000 (Overflow, le nombre n'est pas dans la range de nombre accesible sur 8 bits en ca2)
32) 00000001
- 00000010
----------
= 11111111
33) 00001001
x 00000110
----------
000010010
+ 0000100100
------------
= 0000110110
34) 10000001
- 10000010
----------
= 11111111
35) - 10000000 = 011111111 (Imposible a representer sur 8 bits)
36) 00010100
/ 00000101
----------
00000100
37) 00010111
/ 00001001
----------
00000010 (reste 101)
38)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,32 @@
.data
txt1: .asciiz "Entrez un premier nombre:"
txt2: .asciiz "Entrez un second nombre:"
.text
main:
# print txt1
la $a0, txt1
li $v0, 4
syscall
#read t0
li $v0, 5
syscall
move $t0, $v0
# print txt2
li $v0, 4
la $a0, txt2
syscall
#read t1
li $v0, 5
syscall
move $t1, $v0
# a0 = t0 + t1
add $a0, $t1, $t0
li $v0, 1
syscall
jr $ra

View File

@ -0,0 +1,20 @@
.data
text: .asciiz "Hello I'm in my fct"
.text
main:
# Appel Fonction
or $t0 $zero $ra
jal fct
or $ra $zero $t0
jr $ra
fct:
li $v0, 4
la $a0, text
syscall
jr $ra

View File

@ -0,0 +1,12 @@
main:
li $a0, 5
li $a1, 0
li $v0, 1
j loop
loop:
syscall
addiu $a0, -1
bne $a0, $a1, loop
# bgtz $a0, loop
jr $ra

View File

@ -0,0 +1,10 @@
main:
li $a0, 5
li $a1, 0
j loop
loop:
addiu $a0, -1
bne $a0, $a1, loop
# bgtz $a0, loop
jr $ra

View File

@ -0,0 +1,3 @@
main:
nop
j main

View File

@ -0,0 +1,9 @@
.data
mystr: .asciiz "The answer to live, universe and everything else is.... 42"
.text
main:
la $a0, mystr
li $v0, 4
syscall
jr $ra

View File

@ -0,0 +1,33 @@
.data
question: .asciiz "Entrez un nombre: "
gr: .asciiz "Trop Grand!\n"
pe: .asciiz "Valeur acceptee\n"
.text
main:
la $a0, question
li $v0, 4
syscall
li $v0, 5
syscall
bgt $v0, 10, grand
bgt $v0, 0, petit
jr $ra
grand:
la $a0, gr
li $v0, 4
syscall
j main
petit:
la $a0, pe
li $v0, 4
syscall
lr $a0,
li $v0, 4
syscall
j main

View File

@ -0,0 +1,27 @@
.data
ask: .ascii "Entrez un nombre:"
.text
main:
# Print(ask)
li $v0 4
la $a0 ask
syscall
# read()
li $v0 5
syscall
li $t0 2 #base
divi:
div $v0, $t0
li $v0, 1
mfhi $a0
syscall
mflo $v0
bne $v0, 0, divi
jr $ra

View File

@ -0,0 +1,27 @@
.data
hex: .asciiz "0123456789ABCDEF"
q1: .asciiz "Entrez un nombre"
.text
main:
li $v0, 4
la $a0, q1
syscall
li $v0, 5
syscall
li $t0 16 #base
divi:
div $v0, $t0
mfhi $t2
la $t9, hex
addu $t9, $t9, $t2
lb $a0 0($t9)
li $v0, 11
syscall
mflo $v0
bne $v0, 0, divi
jr $ra

View File

@ -0,0 +1,63 @@
.data
tab: .word case5, case6, case7, case8
q1: .asciiz "Entrez un nombre entre 5 et 8:"
r5: .asciiz "case 5"
r6: .asciiz "case 6"
r7: .asciiz "case 7"
r8: .asciiz "case 8"
.text
main:
# ask a number
li $v0, 4
la $a0, q1
syscall
# read the number
li $v0, 5
syscall
li $t5, 5
li $t4, 4
sub $t1, $v0, $t5
mult $t1, $t4
mflo $t2
# Load addr : tab
la $t1, tab
addu $t1, $t2, $t1
lw $t0,0($t1)
jr $t0
case5:
li $v0, 4
la $a0, r5
syscall
j end_case
case6:
li $v0, 4
la $a0, r6
syscall
j end_case
case7:
li $v0, 4
la $a0, r7
syscall
j end_case
case8:
li $v0, 4
la $a0, r8
syscall
j end_case
end_case:
jr $ra

View File

@ -0,0 +1,5 @@
# TP3
1) Car c'est un exposant de 2.
La memoire fonctionnant en binaire, pour chaques bits ajoutes, nous obtenons une capacites deux fois plus grande

Binary file not shown.