注册 登录
编程论坛 汇编论坛

有段书中代码自己实践时出错

初学编程的人 发布于 2017-09-04 22:31, 2495 次点击
程序代码:

%include "pm.inc"

org 07c00h
jmp LABEL_BEGIN

[SECTION .gdt]
LABEL_GDT: Descriptor 0, 0, 0
LABEL_DESC_CODE32: Descriptor 0, SegCode32Len-1, DA_C+DA_32
LABEL_DESC_VIDEO: Descriptor 0b8000h, 0ffffh, DA_DRW

GdtLen equ $-LABEL_GDT
GdtPtr dw GdtLen-1
dd 0

SelectorCode32 equ LABEL_DESC_CODE32-LABEL_GDT
SelectorVideo equ LABEL_DESC_VIDEO-LABEL_GDT


[SECTION .s16]
[BITS 16]
LABEL_BEGIN:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0100h

xor eax, eax
mov ax, cs
shl eax, 4
add eax, LABEL_SEG_CODE32
mov word [LABEL_DESC_CODE32+2], ax
mov eax, 16
mov byte [LABEL_DESC_CODE32+4], al
mov byte [LABEL_DESC_CODE32+7], ah

xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_GDT
mov dword [GdtPtr+2],?eax

lgdt [GdtPtr]
cli

in al, 92h
or al, 00000010b
out 92h, al

mov eax, cr0
or eax, 1
mov cr0, eax

jmp dword SelectorCode32:0


[SECTION .s32]
[BITS 32]
LABEL_SEG_CODE32:
mov ax, SelectorVideo
mov gs, ax
mov edi, (80*11+79)*2
mov ah, 0ch
mov al, 'P'
mov [gs:edi], ax

jmp $

SegCode32Len  equ $-LABEL_SEG_CODE32


程序代码:

;pm.inc
%macro Desriptor 3
    dw    %2 & 0FFFFh
    dw    %1 & 0FFFFh
    db    (%1 >> 16) & 0FFh
    dw    ((%2 >> 8) & 0F00h) | (%3 & 0F0FFh)
    db    (%1 >> 24) & 0FFh
%endmacro

用nasm编译出现如下错误
boot.asm:7: error: parser: instruction expected
boot.asm:8: error: parser: instruction expected
boot.asm:9: error: parser: instruction expected

不知何解
4 回复
#2
初学编程的人2017-09-05 10:48
编译环境,OS:win10  编译软件: nasm
#3
初学编程的人2017-09-05 14:19
问题解决,原因是书中所列代码段不完整,需要附带光盘的完整pm.inc,书中未说明需要全部代码
#4
初学编程的人2017-09-05 14:19
问题解决,原因是书中所列代码段不完整,需要附带光盘的完整pm.inc,书中未说明需要全部代码
#5
Valenciax2017-09-09 08:46
乐见自行解决问题
1