Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:blc:informatik:efi-2023:assembler [2024/04/02 15:01] Ivo Blöchliger |
lehrkraefte:blc:informatik:efi-2023:assembler [2024/04/23 15:04] (current) Ivo Blöchliger [Funktionsweise einer CPU] |
||
---|---|---|---|
Line 33: | Line 33: | ||
<WRAP todo> | <WRAP todo> | ||
- | Produzieren Sie die Ausgabe 'abcdefghijklmnopqrstuvwxyz' | + | Produzieren Sie die Ausgabe 'abcdefghijklmnopqrstuvwx' |
</ | </ | ||
**Subroutine, | **Subroutine, | ||
Line 92: | Line 92: | ||
<WRAP todo> | <WRAP todo> | ||
Unter Verwendung der obigen Beispiele und subroutinen, | Unter Verwendung der obigen Beispiele und subroutinen, | ||
+ | |||
+ | <hidden Lösungsvorschlag> | ||
+ | <code asm> | ||
+ | MOV A, 237 | ||
+ | MOV C,232 | ||
+ | CALL showByte | ||
+ | HLT | ||
+ | |||
+ | ; Byte in A | ||
+ | ; Address in C | ||
+ | showByte: | ||
+ | PUSH A ; Save registers | ||
+ | PUSH B | ||
+ | PUSH C | ||
+ | ADD C,2 | ||
+ | loopA: | ||
+ | PUSH A ; SAVE A | ||
+ | PUSH 10 ; Push modulo op to stack | ||
+ | CALL mod | ||
+ | INC SP ; Correct Stackpointer | ||
+ | MOV B,A ; digit to B | ||
+ | CALL showDigit | ||
+ | DEC C ; Adjust for next address | ||
+ | POP A ; restore A | ||
+ | DIV 10 | ||
+ | JNZ loopA | ||
+ | POP C | ||
+ | POP B | ||
+ | POP A | ||
+ | RET | ||
+ | |||
+ | </ | ||
+ | </ | ||
</ | </ | ||
Line 178: | Line 211: | ||
Bonus: Implementieren Sie QuickSort. | Bonus: Implementieren Sie QuickSort. | ||
+ | |||
+ | <hidden Animationen auf 7-Segment-Anzeige> | ||
+ | <code asm> | ||
+ | ; Simple example | ||
+ | ; Writes Hello World to the output | ||
+ | |||
+ | start: | ||
+ | |||
+ | MOV B, dataStart | ||
+ | loop: | ||
+ | MOV A, 253 | ||
+ | MOV C, [B] | ||
+ | MOV [A], C | ||
+ | MOV C, [B+1] | ||
+ | MOV [A+1], C | ||
+ | MOV C, [B+2] | ||
+ | MOV [A+2], C | ||
+ | ADD B, 3 | ||
+ | CMP B, dataEnd | ||
+ | JNZ loop | ||
+ | JMP start | ||
+ | |||
+ | |||
+ | |||
+ | dataStart: | ||
+ | DB 8 | ||
+ | DB 8 | ||
+ | DB 8 | ||
+ | |||
+ | DB 0 | ||
+ | DB 8 | ||
+ | DB 12 | ||
+ | |||
+ | DB 0 | ||
+ | DB 0 | ||
+ | DB 14 | ||
+ | |||
+ | DB 0 | ||
+ | DB 0 | ||
+ | DB 7 | ||
+ | |||
+ | DB 0 | ||
+ | DB 1 | ||
+ | DB 3 | ||
+ | |||
+ | DB 1 | ||
+ | DB 1 | ||
+ | DB 1 | ||
+ | |||
+ | DB 33 | ||
+ | DB 1 | ||
+ | DB 0 | ||
+ | |||
+ | DB 49 | ||
+ | DB 0 | ||
+ | DB 0 | ||
+ | |||
+ | DB 56 | ||
+ | DB 0 | ||
+ | DB 0 | ||
+ | |||
+ | DB 24 | ||
+ | DB 8 | ||
+ | DB 0 | ||
+ | |||
+ | dataEnd: | ||
+ | </ | ||
+ | </ | ||
+ | <hidden Animation mit Bytes in Strings codier (unnötig hackisch)> | ||
+ | <code asm> | ||
+ | start: | ||
+ | |||
+ | MOV B, dataStart | ||
+ | loop: | ||
+ | MOV C, [B] | ||
+ | MOV A, [B+6] | ||
+ | MOV [253], C | ||
+ | MOV [254], A | ||
+ | MOV [255], C | ||
+ | INC B | ||
+ | CMP B, dataEnd | ||
+ | JNZ loop | ||
+ | JMP start | ||
+ | |||
+ | |||
+ | |||
+ | dataStart: | ||
+ | DB " | ||
+ | |||
+ | dataEnd: | ||
+ | DB " | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <hidden Quicksort-Implementation> | ||
+ | <code asm> | ||
+ | JMP start | ||
+ | arrayStart: | ||
+ | DB 4 | ||
+ | DB 2 | ||
+ | DB 7 | ||
+ | DB 9 | ||
+ | DB 8 | ||
+ | DB 7 | ||
+ | DB 4 | ||
+ | DB 5 | ||
+ | DB 8 | ||
+ | DB 9 | ||
+ | DB 4 | ||
+ | DB 3 | ||
+ | DB 6 | ||
+ | DB 1 | ||
+ | |||
+ | |||
+ | start: | ||
+ | MOV A, arrayStart | ||
+ | MOV B, start | ||
+ | DEC B | ||
+ | call quicksort | ||
+ | HLT | ||
+ | |||
+ | |||
+ | quicksort: | ||
+ | ;first elements address in A | ||
+ | ;last elements address in B | ||
+ | PUSH D | ||
+ | PUSH C | ||
+ | PUSH B | ||
+ | PUSH A | ||
+ | MOV C,B | ||
+ | SUB C,A | ||
+ | JBE ende ; bail if B-A <= 0 | ||
+ | MOV [a0], A ; save bounds | ||
+ | MOV [b0], B | ||
+ | MOV C, [A] ; Pivot value | ||
+ | INC A | ||
+ | leftloop: | ||
+ | CMP C,[A] | ||
+ | JC rightloop | ||
+ | INC A | ||
+ | CMP A,B | ||
+ | JBE leftloop | ||
+ | |||
+ | rightloop: | ||
+ | CMP C,[B] | ||
+ | JA swapping | ||
+ | DEC B | ||
+ | CMP A,B | ||
+ | JB rightloop | ||
+ | |||
+ | swapping: | ||
+ | CMP A,B | ||
+ | JAE setpivot | ||
+ | MOV D, [A] | ||
+ | PUSH D | ||
+ | MOV D, [B] | ||
+ | MOV [A], D | ||
+ | POP D | ||
+ | MOV [B], D | ||
+ | INC A | ||
+ | DEC B | ||
+ | JMP leftloop | ||
+ | |||
+ | setpivot: | ||
+ | CMP A,[b0] | ||
+ | JBE ok | ||
+ | MOV A,[b0] | ||
+ | INC A | ||
+ | ok: ; swap pivot and [A] | ||
+ | DEC A | ||
+ | MOV [p0], A ; index of pivot | ||
+ | MOV D,[A] | ||
+ | MOV [A], C | ||
+ | MOV C,[a0] | ||
+ | MOV [C], D | ||
+ | ;recursion | ||
+ | MOV A, [a0] | ||
+ | MOV B, [p0] | ||
+ | DEC B | ||
+ | PUSH [p0] ; save p0 and b0 | ||
+ | PUSH [b0] | ||
+ | call quicksort | ||
+ | POP B ; restore p0 and b0 | ||
+ | POP A | ||
+ | INC A | ||
+ | call quicksort | ||
+ | ende: | ||
+ | POP A | ||
+ | POP B | ||
+ | POP C | ||
+ | POP C | ||
+ | RET | ||
+ | |||
+ | |||
+ | a0: DB 0 | ||
+ | b0: DB 0 | ||
+ | p0: DB 0 | ||
+ | |||
+ | </ | ||
+ | </ | ||
</ | </ | ||
===== Hackme ===== | ===== Hackme ===== | ||
Line 249: | Line 485: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== Mögliche Prüfungsfragen ===== | ||
+ | Die Ausgabe auf die drei 7-Segment Anzeigen erfolgt auf die Adressen 253 bis 255. | ||
+ | |||
+ | Die Bits auf der Anzeige sind wie folgt nummeriert: | ||
+ | <code txt> | ||
+ | +--0--+ | ||
+ | 5 1 | ||
+ | :--6--: | ||
+ | 4 2 | ||
+ | +--3--+ | ||
+ | </ | ||