📄 codegen.asm
字号:
model large compiler_text,pascal
include compiler.inc
.code compiler_text
public LoadSegDI
public PushFloat
public PutFwait
public PutEmulInt
public Need8087
public PushReal
public LoadReal
public ConvertOrdinal
public Increment
public PushValue
public PutPush
public FindEmptyReg
public PopValue
public Scale
public BackScale
public MakePtr
public FreeRegs
public LoadValue
public StoreValue
public SwapSegOfs
public AllocStack
public CreateLocalVar
public SetBaseAndSize
public PushSetAddr
public PushWord
public LoadReg
public LoadWord
public StoreReg
public PutMovRMImm
public PutArOpAX
public PutArOp
public PutLogOp
public PutArOpImm
public PutArOpRMImm
public FloatAddOffset
public AddOffset
public PutFloatRM
public PutRM
public AddReg
public PutPrefix
LoadSegDI proc near
call LoadDI
jmp GetSegment
LoadSegDI endp
LoadDI proc near
test [di].exMisc,efBP
jz @@1
mov dx,388dh ; lea di,...
jmp AddReg
@@1: test [di].exMisc,efDI
jz @@3
test [di].exMisc,efDS+efCS+efConst
jnz @@2
cmp [di].exOffset,0
je @@5
@@2: mov ax,0c781h ; add di,...
Invoke PutWord
jmp short @@4
@@3: mov al,0bfh ; mov di,...
Invoke PutByte
@@4: jmp PutOffset
@@5: ret
LoadDI endp
PushFloat proc near
cmp [di].exLocation,elImmediate
jne @@2
les bx,[si].exType
mov al,es:[bx].tdModifier
lea bx,[di].exValue
push ax
Invoke Extended2Float
pop ax
mov bx,10
cmp al,emExtended
je @@1
mov bl,8
cmp al,emSingle
jne @@1
mov bl,4
@@1: dec bx
dec bx
mov ax,word ptr [di+bx].exValue
push bx
call PushWord
pop bx
or bx,bx
jnz @@1
Chain DoneExpr
@@2: cmp [di].exLocation,elMemory
jne @@4
mov al,[di].exModifier
les bx,[si].exType
cmp al,es:[bx].tdModifier
jne @@3
mov cx,es:[bx].tdSizeOf
Invoke UseExpr
call PushMemory
Chain DoneExpr
@@3: Invoke PushExt
@@4: Invoke UseExpr
les bx,[si].exType
mov ax,es:[bx].tdSizeOf
mov dl,0ech ; sub sp,...
call PutArOpImm
mov ax,0e389h ; mov bx,sp
Invoke PutWord
call PutEmulInt
mov al,3ch
Invoke PutByte
mov ax,1f59h ; fstp ss:[bx]
les bx,[si].exType
or al,es:[bx].tdModifier
test al,2
jz @@5
mov ah,3fh
@@5: Invoke PutWord
call PutFwait
Chain DoneExpr
PushFloat endp
PutFwait proc near
mov ax,3dcdh ; fwait
Chain PutWord
PutFwait endp
PutEmulInt proc near
call Need8087
mov al,0cdh ; int
Chain PutByte
PutEmulInt endp
Need8087 proc near
test CompilerOptions,co8087
jz @@1
push ds
mov ds,Dictionary.Segm
or ds:uhFlags,uf8087
pop ds
ret
@@1: mov ax,116
Chain CompileError
Need8087 endp
PushReal proc near
Invoke UseExpr
call _PushReal
Chain DoneExpr
PushReal endp
_PushReal proc near
cmp [di].exLocation,elMemory
jne @@1
mov cx,6
jmp PushMemory
@@1: mov al,lrR1
call LoadReal
mov ax,5352h ; push dx push bx
Invoke PutWord
mov al,50h ; push ax
Chain PutByte
_PushReal endp
LoadReal proc near
cmp [di].exLocation,elRegister
je @@1
mov cl,al
mov ax,lvAX+lvCX*256
call ShiftReal
mov ax,lvBX+lvSI*256
call ShiftReal
mov ax,lvDX+lvDI*256
call ShiftReal
mov [di].exLocation,elRegister
@@1: mov [di].exRegsUsed,erAll
ret
LoadReal endp
ShiftReal proc near
or cl,cl
jz @@1
mov al,ah
@@1: call LoadReg
cmp [di].exLocation,elMemory
jne @@2
add [di].exOffset,2
ret
@@2: mov ax,[di].exValue.W2
mov [di].exValue.W0,ax
mov ax,[di].exValue.W4
mov [di].exValue.W2,ax
ret
ShiftReal endp
ConvertOrdinal proc near
mov cl,[di].exModifier
mov ch,al
cmp [di].exLocation,elImmediate
jne @@3
mov ax,[di].exValue.W0
mov dx,[di].exValue.W2
test ch,emX
jnz @@1
cbw
test ch,emUnsigned
jz @@1
xor ah,ah
@@1: test ch,emXX
jnz @@2
cwd
test ch,emUnsigned
jz @@2
xor dx,dx
@@2: mov [di].exValue.W0,ax
mov [di].exValue.W2,dx
jmp short @@7
@@3: xor ax,ax
xor dx,dx
test ch,emX
jz @@4
test cl,emX
jnz @@4
mov al,98h ; cbw
test cl,emUnsigned
jz @@4
mov ax,0e430h ; xor ah,ah
@@4: test ch,emXX
jz @@5
test cl,emXX
jnz @@5
or [di].exRegsUsed,erDX
mov dl,99h ; cwd
test cl,emUnsigned
jz @@5
mov dx,0d231h ; xor dx,dx
@@5: mov bx,ax
or bx,dx
jnz @@6
cmp [di].exLocation,elAddress
jne @@7
test ch,emX
jnz @@7
@@6: push cx dx ax
Invoke UseExpr
mov al,lvAX
call LoadValue
pop ax
call PutBytes
pop ax
call PutBytes
Invoke DoneExpr
pop cx
@@7: mov [di].exModifier,ch
ret
ConvertOrdinal endp
PutBytes proc near
or ax,ax
jz @@2
or ah,ah
jz @@1
Chain PutWord
@@1: Chain PutByte
@@2: ret
PutBytes endp
Increment proc near
cmp [si].exLocation,elImmediate
jne @@3
Invoke UseExpr
test [di].exModifier,emXX
jnz @@1
cmp [si].exValue.W0,1
jne @@1
cmp [si].exValue.W2,0
jne @@1
mov dl,0feh ; inc
call PutRM
Chain DoneExpr
@@1: mov ax,[si].exValue.W0
push dx
call PutArOpRMImm
pop dx
test [di].exModifier,emXX
jz @@2
add [di].exOffset,2
mov ax,[si].exValue.W2
mov dl,dh
or dl,10h ; adc
call PutArOpRMImm
sub [di].exOffset,2
@@2: Chain DoneExpr
@@3: push dx
xchg si,di
Invoke UseExpr
mov al,[si].exRegsUsed
call FindEmptyReg
xchg si,di
Invoke UseExpr
xchg si,di
xor al,al
call PopValue
xchg si,di
pop dx
mov cl,dh
mov dh,[si].exMisc
shl dh,1
shl dh,1
shl dh,1
mov ch,dh
call PutRM
test [di].exModifier,emXX
jz @@4
add [di].exOffset,2
mov dx,cx
or dx,1010h ; adc
call PutRM
sub [di].exOffset,2
@@4: Chain DoneExpr
Increment endp
PushValue proc near
Invoke UseExpr
call PutPush
Chain DoneExpr
PushValue endp
PutPush proc near
cmp [di].exLocation,elMemory
jne @@2
test [di].exModifier,emX
jz @@5
test [di].exModifier,emXX
jz @@1
add [di].exOffset,2
mov dx,30ffh ; push
call AddReg
sub [di].exOffset,2
@@1: mov dx,30ffh ; push
call AddReg
jmp short @@13
@@2: cmp [di].exLocation,elRegister
je @@6
cmp [di].exLocation,elAddress
je @@8
test CompilerOptions,co286Code
jz @@5
test [di].exModifier,emXX
jz @@3
mov ax,[di].exValue.W2
call PushWord286
@@3: mov ax,[di].exValue.W0
test [di].exModifier,emX
jnz @@4
cbw
@@4: call PushWord286
jmp short @@13
@@5: mov al,lvAX
call LoadValue
@@6: test [di].exModifier,emXX
jz @@7
mov al,52h ; push dx
Invoke PutByte
@@7: mov al,50h ; push ax
Invoke PutByte
jmp short @@13
@@8: test [di].exMisc,efSeg
jnz @@9
call LoadDI
test [di].exModifier,emXX
jz @@12
@@9: test [di].exMisc,efDS+efSS+efCS+efES
jnz @@10
mov al,0b8h ; mov ax,
call LoadSegment
mov al,50h ; push ax
jmp short @@11
@@10: call GetPrefix
or al,6 ; push
@@11: Invoke PutByte
test [di].exModifier,emXX
jz @@13
@@12: mov al,57h ; push di
Invoke PutByte
@@13: mov [di].exLocation,elPushed
ret
PutPush endp
FindEmptyReg proc near
test [di].exModifier,emXX
jnz @@1
test al,erAX
jz @@2
test al,erDX
jz @@3
test al,erCX
jz @@4
test al,erBX
jz @@5
jmp PutPush
@@1: test al,erAX+erDX
jz @@2
test al,erCX+erBX
jz @@4
jmp PutPush
@@2: mov al,lvAX
jmp LoadValue
@@3: mov al,lvDX
jmp LoadValue
@@4: mov al,lvCX
jmp LoadValue
@@5: mov al,lvBX
jmp LoadValue
FindEmptyReg endp
PopValue proc near
cmp [di].exLocation,elPushed
jne @@4
mov [di].exLocation,elRegister
test [di].exModifier,emXX
jnz @@2
mov ah,58h ; pop ax
mov cx,erAX+lvAX*256
test al,cl
jz @@1
mov ah,5ah ; pop dx
mov cx,erDX+lvDX*256
test al,cl
jz @@1
mov ah,59h ; pop cx
mov cx,erCX+lvCX*256
test al,cl
jz @@1
mov ah,5bh ; pop bx
mov cx,erBX+lvBX*256
@@1: or [di].exRegsUsed,cl
mov [di].exMisc,ch
mov al,ah
Chain PutByte
@@2: mov cx,erAX+erDX+lvAX*256
test al,cl
mov ax,5a58h ; pop ax pop dx
jz @@3
mov cx,erCX+erBX+lvCX*256
mov ax,5b59h ; pop cx pop bx
@@3: or [di].exRegsUsed,cl
mov [di].exMisc,ch
Chain PutWord
@@4: ret
PopValue endp
Scale proc near
cmp cx,1
jb @@10
je @@7
mov bx,cx
mov dx,-1
@@1: inc dx
shr bx,1
jnc @@1
jz @@8
cmp cx,7
jae @@10
mov ch,al
push cx
call LoadValue
pop cx
cmp cl,6
jne @@2
call @@5
@@2: mov ax,0f08bh ; mov si,
call @@6
call @@5
cmp cl,5
jne @@3
call @@5
@@3: mov ax,0f001h ; add ,si
jmp short @@6
@@4: call @@5
@@5: mov ax,0e0d1h ; shl ,1
@@6: or ah,ch
Chain PutWord
@@7: ret
@@8: mov cl,dl
mov ch,al
push cx
call LoadValue
pop cx
cmp cl,1
je @@5
test CompilerOptions,co286Code
jnz @@9
cmp cl,2
je @@4
or [di].exRegsUsed,erCX
mov al,0b1h ; mov cl,
mov ah,cl
Invoke PutWord
mov ax,0e0d3h ; shl ax,cl
jmp @@6
@@9: mov ax,0e0c1h ; shl ax,
call @@6
mov al,cl
Chain PutByte
@@10: test CompilerOptions,co286Code
jnz @@12
or [di].exRegsUsed,erDX
cmp [di].exLocation,elRegister
jne @@11
cmp [di].exMisc,lvAX
jne @@11
mov al,0bah ; mov dx,
Invoke PutByte
mov ax,cx
Invoke PutWord
mov ax,0e2f7h ; mul dx
Chain PutWord
@@11: mov al,0b8h ; mov ax,
Invoke PutByte
mov ax,cx
Invoke PutWord
mov dx,20f7h ; mul
call AddReg
mov cl,lvAX
jmp short @@15
@@12: push ax
shl al,1
shl al,1
shl al,1
mov dh,al
mov ax,cx
cbw
cmp ax,cx
jz @@13
mov dl,69h ; imul
call AddReg
mov ax,cx
Invoke PutWord
jmp short @@14
@@13: mov dl,6bh ; imul
call AddReg
mov al,cl
Invoke PutByte
@@14: pop cx
@@15: mov al,1
shl al,cl
mov [di].exLocation,elRegister
mov [di].exMisc,cl
or [di].exRegsUsed,al
ret
Scale endp
BackScale proc near
cmp cx,1
je @@9
mov dx,0f9f7h ; idiv cx
test [di].exModifier,emSigned
jnz @@6
mov bx,cx
mov dx,-1
@@1: inc dx
shr bx,1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -