編程義敎 : 仁濟醫院兒童發展基金

Back
Category : Home

今次教導了幾名青少年開始學習編程,教授了一些編程的基礎技術。我們生活在一個數字化的世界,編程已經成為我們日常生活中不可或缺的一部分。無論是手機應用程序,還是我們使用的各種網站,都是由編程語言創建的。學習編程可以開啟一扇通往創新和創造力的大門,讓我們有能力去創建和控制自己的數字世界。

義教編程是一種強大的力量,可以幫助青少年開始這個旅程。感謝仁濟醫院兒童發展基金提供了一個友好和支持的環境,讓你們可以在專業的指導下學習編程。這些義工老師都是經驗豐富的編程專家,他們熱衷於分享他們的知識和經驗,幫助你們建立堅實的編程基礎。 2024 Jul 20

範例代碼

a.asm:

bits 16
%define ONE    1

org 0x7c00
	mov ax, 0xb800
	mov es, ax
	mov byte [es:0], 'P'
	mov byte [es:1], 4
	mov byte [es:2], 'e'
	mov byte [es:3], 3

loop1:
	jmp loop1

	times   512-($-$$)-2    db      0
	signature       dw      0xaa55

bochsrcSDL.bxrc:

###############################################################
# bochsrc.txt file for DLX Linux disk image.
###############################################################

# how much memory the emulated machine will have
megs: 16

# hard disk
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="hd.img", mode=flat, cylinders=40, heads=16, spt=63

# choose the boot disk.
boot: c

#display_library: term
# other choices: win32 sdl wx carbon amigaos beos macintosh nogui rfb term svga
display_library: sdl2

# where do we send log messages?
log: bochsout.txt

# disable the mouse, since DLX is text only
mouse: enabled=0

magic_break: enabled=1

#debug: action=report
info: action=report
error: action=report
panic: action=report

insertData.sh:

#!/bin/bash

if [ $# != 4 ]; then
	echo "Usage : insertData.sh source dest <source skip position> <dest seek position>"
	exit;
fi

source_size=$(ls -l $1 | awk {'print $5'})
#dest_size=$(ls -l $2 | awk {'print $5'})
total_seek_size=$((source_size + $4))
#dd if=$2 of=insertData_temp skip=$total_seek_size ibs=1 obs=1MB > /dev/null
if [ $4 = 0 ]; then
	rm -fr first
	touch first
else
	echo "dd if=$2 of=first bs=$4 count=1";
	dd if=$2 of=first bs=$4 count=1
fi

#### back #####
echo "dd if=$2 of=back skip=1 bs=$total_seek_size";
dd if=$2 of=back skip=1 bs=$total_seek_size

cat first $1 back > $2

rm -fr first back

編譯指令

nasm a.asm -l a.lst
./insertData.sh a hd.img 0 0
bochs -f bochsrcSDL.bxrc

下載nasm https://www.nasm.us/

下載bochs https://bochs.sourceforge.io/ , 如果在linux或mac,可以試下自己build

./configure --enable-debugger --enable-debugger-gui --with-sdl2 --with-nogui --with-term
make -j
make install

Asm例子

a.asm:

org 0x7c00
	mov	ax,1
	mov	bx,2
	add ax, bx   ; ax = ax + bx
	inc ax
	sub ax, bx	 ; ax = ax - bx

	mov ah, byte [ds:bx]

	xor ch,ch    ; set zero
	mov byte [ds:bx], ch
	
loop1:
	jmp loop1

	times   512-($-$$)-2    db      0
	signature       dw      0xaa55

bochsrcSDL.bxrc:

###############################################################
# bochsrc.txt file for DLX Linux disk image.
###############################################################

# how much memory the emulated machine will have
megs: 16

# filename of ROM images
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest

# what disk images will be used
#floppya: 1_44=../bootimage, status=inserted
#floppyb: 1_44=floppyb.img, status=inserted

# hard disk
#ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
#ata0-master: type=disk, path="hd10meg.img", cylinders=306, heads=4, spt=17
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
#ata0-master: type=disk, path="10mb.img", mode=flat, cylinders=20, heads=16, spt=63
ata0-master: type=disk, path="hd.img", mode=flat, cylinders=40, heads=16, spt=63
#ata0-master: type=disk, path="../hd.img", mode=flat, cylinders=203, heads=16, spt=63	# 100MB
#ata0-master: type=disk, path="../harddisk", mode=flat, cylinders=2080, heads=16, spt=63   # 1GB

# choose the boot disk.
boot: c

#display_library: term
# other choices: win32 sdl wx carbon amigaos beos macintosh nogui rfb term svga
display_library: sdl2

# where do we send log messages?
log: bochsout.txt

# disable the mouse, since DLX is text only
mouse: enabled=0

# enable key mapping, using US layout as default.
#
# NOTE: In Bochs 1.4, keyboard mapping is only 100% implemented on X windows.
# However, the key mapping tables are used in the paste function, so
# in the DLX Linux example I'm enabling keyboard_mapping so that paste
# will work.  Cut&Paste is currently implemented on win32 and X windows only.

#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-fr.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-de.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-es.map

magic_break: enabled=1

#debug: action=report
info: action=report
error: action=report
panic: action=report

insertData.sh:

#!/bin/bash

if [ $# != 4 ]; then
	echo "Usage : insertData.sh source dest <source skip position> <dest seek position>"
	exit;
fi

source_size=$(ls -l $1 | awk {'print $5'})
#dest_size=$(ls -l $2 | awk {'print $5'})
total_seek_size=$((source_size + $4))
#dd if=$2 of=insertData_temp skip=$total_seek_size ibs=1 obs=1MB > /dev/null
if [ $4 = 0 ]; then
	rm -fr first
	touch first
else
	echo "dd if=$2 of=first bs=$4 count=1";
	dd if=$2 of=first bs=$4 count=1
fi

#### back #####
echo "dd if=$2 of=back skip=1 bs=$total_seek_size";
dd if=$2 of=back skip=1 bs=$total_seek_size

cat first $1 back > $2

rm -fr first back

Compile指令:

nasm a.asm -l a.lst
dd if=/dev/zero of=hd.img count=3072 bs=10240
./insertData.sh a hd.img 0 0
bochs -q -f bochsrcSDL.bxrc

Thank you HKOSCON, their Chairman Mr Sammy, and all members for the chance to present there

終於找到一位有心人Charles Ng先生帶領大家成立Embedded System Special Interest Group,本會和吳先生承諾呢個SIG會last for最少一年,吳先生會搞兩次workshop,會長亦都會一對一搞另多兩次workshop以作支持。吳先生是業界從事嵌入式開發超過幾十年之專業人士,佢自己實作左塊PCB可以mount raspberry pi cm上去,佢會舉辦workshop教一教大家點做,請大家支持。

吳先生作品