返回

基于“元神”操作系统开发软件

【开发流程】

  • 1. 用FASM汇编语言等编写代码。例如,将下面的demo1或demo2复制保存为demo.asm
  • 2. 编译生成可执行文件。例如,执行命令“fasm.exe demo.asm demo.bin”以生成可执行文件demo.bin
  • 3. 将可执行文件复制到元神系统可访问的磁盘。例如,将demo.bin复制到HOS.BIN所在U盘的根目录
  • 4. 启动元神系统并运行可执行文件。例如:用元神系统所在U盘开机启动系统,执行“ZX demo.bin”
  • 【demo1】

        use32
    
        START:
            pusha
            
            call demo1
            
            popa
            iret
    
    
        ;print string at specified coordinate, e.g y=10 and x=2
        demo1:
            pusha
            mov esi,hello_text
            mov ebx, 10
            mov ecx, 2
            call print_string
            popa
            ret
    
        ;print string
        ;input:
        ;	esi: address to string
        ;	ebx: y position to print
        ;	ecx: x position to print
        print_string:
            pusha
            xor eax, eax
            imul edi, ebx, 80*2
            add edi, ecx
            add edi, ecx
            mov ah, 0x0F
        .next_char:
            lodsb
            cmp al, 0
            je .end
            mov word [gs:edi], ax
            add edi, 2
            jmp .next_char
            .end:
            popa
            ret
     
        hello_text db 'Hello world!',0
    
        

    【demo2】

        use32
    
        START:
            pusha
            
            call demo2
            
            popa
            iret
    
        cursor_x equ 0x02004B10
        cursor_y equ 0x02004B12
    
        ;print string at current cursor position which is readed from OS
        demo2:
            pusha
            
            mov esi,hello_text
            movzx ebx, word [fs:cursor_y]
            movzx ecx, word [fs:cursor_x]
            call print_string
            
            add word [fs:cursor_y], 1
            
            popa
            ret
    
        ;print string
        ;input:
        ;	esi: address to string
        ;	ebx: y position to print
        ;	ecx: x position to print
        print_string:
            pusha
            xor eax, eax
            imul edi, ebx, 80*2
            add edi, ecx
            add edi, ecx
            mov ah, 0x0F
        .next_char:
            lodsb
            cmp al, 0
            je .end
            mov word [gs:edi], ax
            add edi, 2
            jmp .next_char
            .end:
            popa
            ret
    
        hello_text db 'Hello world!',0