Skip to content
Snippets Groups Projects
Commit b1167b8b authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Vortragsfolien, Beispiele (C, Assembler, Redcode) und Skripte 18.4.2023

parent 383d8e54
No related branches found
No related tags found
No related merge requests found
Showing
with 600 additions and 0 deletions
%.elf: %.c
avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@
%.hex: %.elf
avr-objcopy -O ihex $< $@
download:
./download.sh
#include <avr/io.h>
#define F_CPU 8000000
#include <util/delay.h>
int main (void)
{
DDRB = 0xff; // alle 8 Ausgänge als Outputs verwenden ("pinMode" für alle 8)
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
{
_delay_ms (500);
PORTB = 0x00;
_delay_ms (500);
PORTB = 0x20;
}
return 0;
}
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C9458000C940000DD
:100080008FEF84B980E285B92FEF34E39CE02150F3
:1000900030409040E1F700C0000015B82FEF34E386
:1000A0009CE0215030409040E1F700C00000EBCFD1
:0400B000F894FFCFF2
:00000001FF
.file "blink-01.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
ldi r24,lo8(-1) ; #include <avr/io.h>
out 0x4,r24 ;
ldi r24,lo8(32) ; #define F_CPU 8000000
.L3: ; #include <util/delay.h>
out 0x5,r24 ;
ldi r18,lo8(799999) ; int main (void)
ldi r19,hi8(799999) ; {
ldi r25,hlo8(799999) ; DDRB = 0xff; // alle 8 Ausgänge als Outputs verwenden ("pinMode" für alle 8)
1: subi r18,1 ; PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
sbci r19,0 ; while (1)
sbci r25,0 ; {
brne 1b ; _delay_ms (500);
rjmp . ; PORTB = 0x00;
nop ; _delay_ms (500);
out 0x5,__zero_reg__ ; PORTB = 0x20;
ldi r18,lo8(799999) ; }
ldi r19,hi8(799999) ; return 0;
ldi r25,hlo8(799999) ; }
1: subi r18,1
sbci r19,0
sbci r25,0
brne 1b
rjmp .
nop
rjmp .L3
.size main, .-main
.ident "GCC: (GNU) 5.4.0"
.file "blink-01.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.global __mulsf3
.global __ltsf2
.global __gtsf2
.global __fixunssfsi
.text
.global main
.type main, @function
main: ; #include <avr/io.h>
push r28 ;
push r29 ; #define F_CPU 8000000
in r28,__SP_L__ ; #include <util/delay.h>
in r29,__SP_H__ ;
sbiw r28,28 ; int main (void)
in __tmp_reg__,__SREG__ ; {
cli ; DDRB = 0xff; // alle 8 Ausgänge als Outputs verwenden ("pinMode" für alle 8)
out __SP_H__,r29 ; PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
out __SREG__,__tmp_reg__ ; while (1)
out __SP_L__,r28 ; {
/* prologue: function */ ; _delay_ms (500);
/* frame size = 28 */ ; PORTB = 0x00;
/* stack size = 30 */ ; _delay_ms (500);
.L__stack_usage = 30 ; PORTB = 0x20;
ldi r24,lo8(36) ; }
ldi r25,0 ; return 0;
ldi r18,lo8(-1) ; }
movw r30,r24
st Z,r18
ldi r24,lo8(37)
ldi r25,0
ldi r18,lo8(32)
movw r30,r24
st Z,r18
.L18:
ldi r24,0
ldi r25,0
ldi r26,lo8(-6)
ldi r27,lo8(67)
std Y+1,r24
std Y+2,r25
std Y+3,r26
std Y+4,r27
ldi r18,0
ldi r19,0
ldi r20,lo8(-6)
ldi r21,lo8(68)
ldd r22,Y+1
ldd r23,Y+2
ldd r24,Y+3
ldd r25,Y+4
call __mulsf3
movw r26,r24
movw r24,r22
std Y+19,r24
std Y+20,r25
std Y+21,r26
std Y+22,r27
ldi r18,0
ldi r19,0
ldi r20,lo8(-128)
ldi r21,lo8(63)
ldd r22,Y+19
ldd r23,Y+20
ldd r24,Y+21
ldd r25,Y+22
call __ltsf2
tst r24
brge .L23
ldi r24,lo8(1)
ldi r25,0
std Y+24,r25
std Y+23,r24
rjmp .L4
.L23:
ldi r18,0
ldi r19,lo8(-1)
ldi r20,lo8(127)
ldi r21,lo8(71)
ldd r22,Y+19
ldd r23,Y+20
ldd r24,Y+21
ldd r25,Y+22
call __gtsf2
cp __zero_reg__,r24
brge .L24
ldi r18,0
ldi r19,0
ldi r20,lo8(32)
ldi r21,lo8(65)
ldd r22,Y+1
ldd r23,Y+2
ldd r24,Y+3
ldd r25,Y+4
call __mulsf3
movw r26,r24
movw r24,r22
movw r22,r24
movw r24,r26
call __fixunssfsi
movw r26,r24
movw r24,r22
std Y+24,r25
std Y+23,r24
rjmp .L7
.L8:
ldi r24,lo8(-56)
ldi r25,0
std Y+26,r25
std Y+25,r24
ldd r24,Y+25
ldd r25,Y+26
/* #APP */
; 105 "/usr/lib/avr/include/util/delay_basic.h" 1
1: sbiw r24,1
brne 1b
; 0 "" 2
/* #NOAPP */
std Y+26,r25
std Y+25,r24
ldd r24,Y+23
ldd r25,Y+24
sbiw r24,1
std Y+24,r25
std Y+23,r24
.L7:
ldd r24,Y+23
ldd r25,Y+24
or r24,r25
brne .L8
rjmp .L9
.L24:
ldd r22,Y+19
ldd r23,Y+20
ldd r24,Y+21
ldd r25,Y+22
call __fixunssfsi
movw r26,r24
movw r24,r22
std Y+24,r25
std Y+23,r24
.L4:
ldd r24,Y+23
ldd r25,Y+24
std Y+28,r25
std Y+27,r24
ldd r24,Y+27
ldd r25,Y+28
/* #APP */
; 105 "/usr/lib/avr/include/util/delay_basic.h" 1
1: sbiw r24,1
brne 1b
; 0 "" 2
/* #NOAPP */
std Y+28,r25
std Y+27,r24
.L9:
ldi r24,lo8(37)
ldi r25,0
movw r30,r24
st Z,__zero_reg__
ldi r24,0
ldi r25,0
ldi r26,lo8(-6)
ldi r27,lo8(67)
std Y+5,r24
std Y+6,r25
std Y+7,r26
std Y+8,r27
ldi r18,0
ldi r19,0
ldi r20,lo8(-6)
ldi r21,lo8(68)
ldd r22,Y+5
ldd r23,Y+6
ldd r24,Y+7
ldd r25,Y+8
call __mulsf3
movw r26,r24
movw r24,r22
std Y+9,r24
std Y+10,r25
std Y+11,r26
std Y+12,r27
ldi r18,0
ldi r19,0
ldi r20,lo8(-128)
ldi r21,lo8(63)
ldd r22,Y+9
ldd r23,Y+10
ldd r24,Y+11
ldd r25,Y+12
call __ltsf2
tst r24
brge .L25
ldi r24,lo8(1)
ldi r25,0
std Y+14,r25
std Y+13,r24
rjmp .L12
.L25:
ldi r18,0
ldi r19,lo8(-1)
ldi r20,lo8(127)
ldi r21,lo8(71)
ldd r22,Y+9
ldd r23,Y+10
ldd r24,Y+11
ldd r25,Y+12
call __gtsf2
cp __zero_reg__,r24
brge .L26
ldi r18,0
ldi r19,0
ldi r20,lo8(32)
ldi r21,lo8(65)
ldd r22,Y+5
ldd r23,Y+6
ldd r24,Y+7
ldd r25,Y+8
call __mulsf3
movw r26,r24
movw r24,r22
movw r22,r24
movw r24,r26
call __fixunssfsi
movw r26,r24
movw r24,r22
std Y+14,r25
std Y+13,r24
rjmp .L15
.L16:
ldi r24,lo8(-56)
ldi r25,0
std Y+16,r25
std Y+15,r24
ldd r24,Y+15
ldd r25,Y+16
/* #APP */
; 105 "/usr/lib/avr/include/util/delay_basic.h" 1
1: sbiw r24,1
brne 1b
; 0 "" 2
/* #NOAPP */
std Y+16,r25
std Y+15,r24
ldd r24,Y+13
ldd r25,Y+14
sbiw r24,1
std Y+14,r25
std Y+13,r24
.L15:
ldd r24,Y+13
ldd r25,Y+14
or r24,r25
brne .L16
rjmp .L17
.L26:
ldd r22,Y+9
ldd r23,Y+10
ldd r24,Y+11
ldd r25,Y+12
call __fixunssfsi
movw r26,r24
movw r24,r22
std Y+14,r25
std Y+13,r24
.L12:
ldd r24,Y+13
ldd r25,Y+14
std Y+18,r25
std Y+17,r24
ldd r24,Y+17
ldd r25,Y+18
/* #APP */
; 105 "/usr/lib/avr/include/util/delay_basic.h" 1
1: sbiw r24,1
brne 1b
; 0 "" 2
/* #NOAPP */
std Y+18,r25
std Y+17,r24
.L17:
ldi r24,lo8(37)
ldi r25,0
ldi r18,lo8(32)
movw r30,r24
st Z,r18
rjmp .L18
.size main, .-main
.ident "GCC: (GNU) 5.4.0"
#include <stdio.h>
int main (void)
{
int a = 3;
int b = 7;
int c = a + b;
printf ("c = %d\n", c);
return 0;
}
.file "calc-01.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "c = %d\n"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc ; #include <stdio.h>
subq $8, %rsp ;
.cfi_def_cfa_offset 16 ; int main (void)
movl $10, %esi ; {
leaq .LC0(%rip), %rdi ; int a = 3;
movl $0, %eax ; int b = 7;
call printf@PLT ; int c = a + b;
movl $0, %eax ; printf ("c = %d\n", c);
addq $8, %rsp ; return 0;
.cfi_def_cfa_offset 8 ; }
ret
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
.file "calc-01.c"
.text
.section .rodata
.LC0:
.string "c = %d\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6 ; #include <stdio.h>
subq $16, %rsp ;
movl $3, -4(%rbp) ; int main (void)
movl $7, -8(%rbp) ; {
movl -4(%rbp), %edx ; int a = 3;
movl -8(%rbp), %eax ; int b = 7;
addl %edx, %eax ; int c = a + b;
movl %eax, -12(%rbp) ; printf ("c = %d\n", c);
movl -12(%rbp), %eax ; return 0;
movl %eax, %esi ; }
leaq .LC0(%rip), %rdi
movl $0, %eax
call printf@PLT
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
int main (void)
{
volatile int a = 3;
volatile int b = 7;
volatile int c = a + b;
printf ("c = %d\n", c);
return 0;
}
.file "calc-02.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "c = %d\n"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $24, %rsp
.cfi_def_cfa_offset 32 ; #include <stdio.h>
movl $3, 12(%rsp) ;
movl $7, 8(%rsp) ; int main (void)
movl 12(%rsp), %eax ; {
movl 8(%rsp), %edx ; volatile int a = 3;
addl %edx, %eax ; volatile int b = 7;
movl %eax, 4(%rsp) ; volatile int c = a + b;
movl 4(%rsp), %esi ; printf ("c = %d\n", c);
leaq .LC0(%rip), %rdi ; return 0;
movl $0, %eax ; }
call printf@PLT
movl $0, %eax
addq $24, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
volatile int a = 3;
volatile int b = 7;
int main (void)
{
volatile static int c = a + b;
printf ("c = %d\n", c);
return 0;
}
.file "calc-03.c"
#include <stdio.h>
volatile int a = 3;
volatile int b = 7;
int main (void)
{
volatile static int c;
c = a + b;
printf ("c = %d\n", c);
return 0;
}
.file "calc-04.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "c = %d\n"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movl a(%rip), %eax
movl b(%rip), %edx
addl %edx, %eax ; #include <stdio.h>
movl %eax, c.2399(%rip) ;
movl c.2399(%rip), %esi ; volatile int a = 3;
leaq .LC0(%rip), %rdi ; volatile int b = 7;
movl $0, %eax ;
call printf@PLT ; int main (void)
movl $0, %eax ; {
addq $8, %rsp ; volatile static int c;
.cfi_def_cfa_offset 8 ; c = a + b;
ret ; printf ("c = %d\n", c);
.cfi_endproc ; return 0;
.LFE11: ; }
.size main, .-main
.local c.2399
.comm c.2399,4,4
.globl b
.data
.align 4
.type b, @object
.size b, 4
b:
.long 7
.globl a
.align 4
.type a, @object
.size a, 4
a:
.long 3
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
port=$(ls -rt /dev/ttyACM* | tail -1)
echo avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1)
avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) 2>/dev/null
;redcode
;name Dwarf
;author A. K. Dewdney
;strategy Throw DAT bombs around memory, hitting every 4th memory cell.
;strategy This program was presented in the first Corewar article.
;assert 1
bomb DAT #0
dwarf ADD #4, bomb
MOV bomb, @bomb
JMP dwarf
END dwarf ; Programs start at the first line unless
; an "END start" pseudo-op appears to indicate
; the first logical instruction. Also, nothing
; after the END instruction will be assembled.
;name Knirps
;assert 1
start mov 0, 1
end start
../common/logo-hochschule-bochum-cvh-text-v2.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
;name Mice
;author Chip Wendell
;assert 1
ptr dat #0
start mov #12, ptr ; n = 12
loop mov @ptr, <dest ; *dest = *(ptr+(*ptr))
djn loop, ptr ; if(--ptr != 0)
; goto loop
spl @dest ; split(*dest)
add #653, dest ; dest += 653
jmz start, ptr ; if(!ptr)
; goto start
dest dat #833
end start
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment