注意,在bochsrcSDL.bxrc不需要這兩句,否則就會做成video framebuffer 0xb8000不能使用
範例代碼
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
############################################################### # 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
#!/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
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
Stack例子:
import java.util.Stack; public class Example6 { public static void main(String args[]) { Stack<String> s = new Stack(); s.add("A"); s.add("B"); s.add("C"); s.remove(1); System.out.println(s.size()); System.out.println(s.pop()); if (!s.empty()) { System.out.println(s.pop()); } System.out.println(s.pop()); if (!s.empty()) { System.out.println(s.pop()); } } }
LinkedList例子:
import java.util.LinkedList; public class Example6 { public static void main(String args[]) { LinkedList<String> list = new LinkedList(); list.add("Peter 1"); list.add("Peter 2"); list.add("Peter 3"); for (int x = 0; x < list.size(); x++) { System.out.println(list.get(x)); } } }
注意 : 如果用VSCode打Code,淺灰式e:只是提示不是真正代碼,不用打去你段Code到
public class Example1{ public static void main(String args[]){ int score=55; if (score >= 80){ System.out.println("A"); }else if (score >= 60){ System.out.println("B"); }else if (score >= 40){ System.out.println("C"); }else{ System.out.println("F"); } System.out.println("End"); } }
class Example1{ public static void main(String args[]){ System.out.println("Hello World"); } }
Compile指令
javac Example1.java
java Example1
首先打錯字唔洗驚, 睇下個Error Message, 佢會有個箭咀指住大約錯邊個位, 同埋有個行數, 跟住就可以揾到錯邊
錯誤張文件名Save做.java.txt, 所有Java文件必需要用.java做尾. 你地係notebook到要簡下面嘅撰項
Get in HKPS website, you see "Hour Of Code" menu on top
If you are not registered yet, you jump in above page. Two options: register for teen or adult
This is the main screen, since we don't have many courses yet, so no search bar. "On going" means the course still has lessons, you may ask teacher questions. "Done" means the course is ended, no question to teacher.
View course info and video play back
McCode is a weekly event for coding enthusiasts who want to share their passion, learn new skills, and enjoy some delicious food. Every week, we meet at a local McDonald’s restaurant and work on different coding projects, challenges, and tutorials. Whether you are a beginner or an expert, you are welcome to join us and have fun with coding. McCode is a great opportunity to network with other coders, get feedback on your work, and discover new tools and resources. Plus, you get to enjoy some tasty burgers, fries, and drinks while you code. What’s not to love? If you are interested in joining McCode, please visit our website and sign up for our newsletter. We hope to see you soon at McCode, the coding event that satisfies your hunger for learning and eating.