📄 codegen.asm
字号:
jnc @@1
jnz @@5
cmp dl,1
je @@3
test CompilerOptions,co286Code
jnz @@4
cmp dl,2
je @@2
or [di].exRegsUsed,erCX
mov al,0b1h ; mov cl,
mov ah,dl
Invoke PutWord
mov ax,0e8d3h ; shr ax,cl
Chain PutWord
@@2: call @@3
@@3: mov ax,0e8d1h ; shr ax,1
Chain PutWord
@@4: mov ax,0e8c1h ; shr ax,
Invoke PutWord
mov al,dl
Chain PutByte
@@5: mov dx,0f1f7h ; div cx
test [di].exModifier,emUnsigned
jnz @@7
@@6: mov al,99h ; cwd
Invoke PutByte
jmp short @@8
@@7: mov ax,0d231h ; xor dx,dx
Invoke PutWord
@@8: mov al,0b9h ; mov cx,
Invoke PutByte
mov ax,cx
Invoke PutWord
mov ax,dx
Invoke PutWord
or [di].exRegsUsed,erCX+erDX
@@9: ret
BackScale endp
MakePtr proc near
mov al,erAX
call FreeRegs
xchg si,di
mov al,lvDX
call LoadValue
xchg si,di
ret
MakePtr endp
FreeRegs proc near
test [si].exRegsUsed,al
jnz @@1
Invoke UseExpr
mov al,lvAX
call LoadValue
xchg si,di
Invoke UseExpr
xchg si,di
ret
@@1: push ax
or al,[di].exRegsUsed
push ax
xchg si,di
Invoke UseExpr
pop ax
call FindEmptyReg
xchg si,di
Invoke UseExpr
mov al,lvAX
call LoadValue
xchg si,di
pop ax
call PopValue
xchg si,di
ret
FreeRegs endp
LoadValue proc near
mov cl,al
test [di].exModifier,emXX
jz @@1
call LoadReg
mov ax,2
call SwapSegOfs
mov al,cl
add al,2
call LoadReg
mov al,erAX+erDX
jmp short @@2
@@1: call LoadReg
mov al,erAX
@@2: shl al,cl
mov [di].exLocation,elRegister
or [di].exRegsUsed,al
mov [di].exMisc,cl
ret
LoadValue endp
StoreValue proc near
mov cl,al
call StoreReg
test [di].exModifier,emXX
jz @@1
add [di].exOffset,2
mov al,cl
add al,2
call StoreReg
sub [di].exOffset,2
@@1: ret
StoreValue endp
SwapSegOfs proc near
cmp [di].exLocation,elMemory
jne @@1
add [di].exOffset,ax
ret
@@1: cmp [di].exLocation,elRegister
jne @@2
add [di].exMisc,al
ret
@@2: cmp [di].exLocation,elImmediate
jne @@3
mov ax,[di].exValue.Offs
xchg ax,[di].exValue.Segm
mov [di].exValue.Offs,ax
ret
@@3: xor [di].exMisc,efSeg
ret
SwapSegOfs endp
AllocStack proc near
mov bx,ax
mov ax,TempLocalsSize
sub ax,bx
test CompilerOptions,coWordAlign
jz @@1
cmp bx,1
je @@1
and ax,0fffeh
@@1: mov TempLocalsSize,ax
mov bx,LocalsSize
or bx,bx
jz @@2
cmp ax,bx
jae @@3
@@2: mov LocalsSize,ax
@@3: ret
AllocStack endp
CreateLocalVar proc near
call AllocStack
mov dx,3e8dh ; lea di,
call AddOffset
mov ax,5716h ; push ss push di
Invoke PutWord
mov [di].exLocation,elStack
ret
CreateLocalVar endp
SetBaseAndSize proc near
mov al,es:[bx].tdSizeOf.B0
mov cx,es:[bx].stBase.Offs
mov bx,es:[bx].stBase.Segm
mov es,es:[bx]
mov bx,cx
mov ah,es:[bx].itLowerBound.B0
mov cl,3
shr ah,cl
ret
SetBaseAndSize endp
PushSetAddr proc near
call SetBaseAndSize
PushWord label near
test CompilerOptions,co286Code
jnz PushWord286
mov dx,ax
mov al,lvAX
call LoadWord
mov al,50h ; push ax
Chain PutByte
PushSetAddr endp
PushWord286 proc near
mov dx,ax
cbw
cmp ax,dx
jne @@1
mov ah,al
mov al,6ah ; push
Chain PutWord
@@1: mov al,68h ; push
Invoke PutByte
mov ax,dx
Chain PutWord
PushWord286 endp
PushMemory proc near
add [di].exOffset,cx
shr cx,1
@@1: sub [di].exOffset,2
mov dx,30ffh ; push
call AddReg
loop @@1
ret
PushMemory endp
LoadReg proc near
cmp [di].exLocation,elMemory
jne @@2
cmp al,lvAX
jne @@3
test [di].exMisc,efBP+efDI
jnz @@3
call PutPrefix
mov al,0a1h ; mov ax,
test [di].exModifier,emX
jnz @@1
mov al,0a0h ; mov al,
@@1: Invoke PutByte
jmp PutOffset
@@2: cmp [di].exLocation,elRegister
jne @@4
cmp al,[di].exMisc
jne @@3
ret
@@3: mov dl,8ah ; mov
shl al,1
shl al,1
shl al,1
mov dh,al
jmp PutRM
@@4: cmp [di].exLocation,elAddress
jne @@9
test [di].exMisc,efSeg
jnz @@7
test [di].exMisc,efBP
jnz @@6
test [di].exMisc,efDI
jnz @@5
test [di].exMisc,efDS+efCS+efConst
jz @@10
or al,0b8h ; mov
Invoke PutByte
jmp PutOffset
@@5: test [di].exMisc,efDS+efCS+efConst
jnz @@6
cmp [di].exOffset,0
jne @@6
mov dl,al
mov ax,0f889h ; mov ,di
or ah,dl
Chain PutWord
@@6: mov dl,8dh ; lea
shl al,1
shl al,1
shl al,1
mov dh,al
jmp AddReg
@@7: test [di].exMisc,efDS+efSS+efCS+efES
jz @@8
mov dl,al
call GetPrefix
or dl,al
mov ax,0c08ch ; mov ax,
or ah,dl
Chain PutWord
@@8: or al,0b8h ; mov ax,
jmp LoadSegment
@@9: test [di].exModifier,emX
jnz @@10
or al,0b0h ; mov al,
mov ah,[di].exValue.B0
Chain PutWord
@@10: mov dx,[di].exValue.W0
LoadWord label near
or dx,dx
jz @@11
or al,0b8h ; mov ax,
Invoke PutByte
mov ax,dx
Chain PutWord
@@11: mov ah,0c0h
or ah,al
shl al,1
shl al,1
shl al,1
or ah,al
mov al,31h ; xor
Chain PutWord
LoadReg endp
StoreReg proc near
cmp al,lvAX
jne @@2
test [di].exMisc,efBP+efDI
jnz @@2
call PutPrefix
mov al,0a3h ; mov ,ax
test [di].exModifier,emX
jnz @@1
mov al,0a2h ; mov ,al
@@1: Invoke PutByte
jmp PutOffset
@@2: mov dl,88h ; mov
shl al,1
shl al,1
shl al,1
mov dh,al
jmp PutRM
StoreReg endp
PutMovRMImm proc near
mov cx,ax
mov dx,0c6h ; mov
call PutRM
mov ax,cx
test [di].exModifier,emX
jz @@1
Chain PutWord
@@1: Chain PutByte
PutMovRMImm endp
PutArOpAX proc near
cmp [di].exLocation,elImmediate
jne @@2
mov al,dl
test [di].exModifier,emX
jz @@1
or al,5
Invoke PutByte
mov ax,[di].exValue.W0
Chain PutWord
@@1: or al,4
mov ah,[di].exValue.B0
Chain PutWord
@@2: or dl,2
xor dh,dh
jmp PutRM
PutArOpAX endp
PutArOp proc near
cmp [di].exLocation,elImmediate
jne @@1
mov ax,[di].exValue.W0
or dl,0c2h
jmp PutArOpImm
@@1: or dl,3
mov dh,10h
jmp AddReg
PutArOp endp
PutLogOp proc near
cmp [di].exLocation,elImmediate
jne @@1
or dl,0c2h
mov ah,dl
mov al,81h
Invoke PutWord
mov ax,[di].exValue.W0
Chain PutWord
@@1: or dl,3
mov dh,10h
jmp AddReg
PutLogOp endp
PutArOpImm proc near
mov cx,ax
cbw
cmp ax,cx
jne @@1
mov ah,dl
mov al,83h
Invoke PutWord
mov al,cl
Chain PutByte
@@1: mov ah,dl
mov al,81h
Invoke PutWord
mov ax,cx
Chain PutWord
PutArOpImm endp
PutArOpRMImm proc near
mov cx,ax
mov dh,dl
mov dl,80h
test [di].exModifier,emX
jz @@1
mov dl,83h
cbw
cmp cx,ax
je @@1
mov dl,81h
call AddReg
mov ax,cx
Chain PutWord
@@1: call AddReg
mov al,cl
Chain PutByte
PutArOpRMImm endp
FloatAddOffset proc near
push ax
call PutEmulInt
pop ax
sub dl,0a4h
AddOffset label near
mov cl,dh
and cl,7
cmp cl,6
je @@1
or ax,ax
jnz @@1
mov ax,dx
Chain PutWord
@@1: mov cx,ax
cbw
cmp ax,cx
jne @@2
or dh,40h
mov ax,dx
Invoke PutWord
mov al,cl
Chain PutByte
@@2: or dh,80h
mov ax,dx
Invoke PutWord
mov ax,cx
Chain PutWord
FloatAddOffset endp
PutFloatRM proc near
test [di].exMisc,efDS+efBP
jz @@1
call PutEmulInt
sub dl,0a4h
jmp short @@3
@@1: call GetSegment
push ax
call PutEmulInt
mov al,3ch
Invoke PutByte
pop ax
shl al,1
shl al,1
shl al,1
xor dl,al
jmp short @@3
PutRM label near
test [di].exModifier,emX
jz AddReg
or dl,1
AddReg label near
cmp [di].exLocation,elRegister
jne @@2
or dh,[di].exMisc
or dh,0c0h
mov ax,dx
Chain PutWord
@@2: call PutPrefix
@@3: mov al,[di].exMisc
test al,efBP
jnz @@4
or dh,6
test al,efDI
jz @@7
xor dh,3
test al,efDS+efCS+efConst
jnz @@6
cmp [di].exOffset,0
jne @@5
mov ax,dx
Chain PutWord
@@4: or dh,6
test al,efDI
jz @@5
xor dh,5
@@5: mov ax,[di].exOffset
cbw
cmp ax,[di].exOffset
jne @@6
or dh,40h
mov ax,dx
Invoke PutWord
mov ax,[di].exOffset
Chain PutByte
@@6: or dh,80h
@@7: mov ax,dx
Invoke PutWord
PutOffset label near
test [di].exMisc,efDS+efCS+efConst
jnz @@8
mov ax,[di].exOffset
Chain PutWord
@@8: push cx
mov ax,[di].exSegment
mov bx,[di].exMap
mov dx,[di].exOffset
test [di].exMisc,efDS
jnz @@9
mov cx,ffCode+ffOffs
test [di].exMisc,efCS
jnz @@10
mov cx,ffProc+ffOffs
jmp short @@10
@@9: mov cx,ffConst+ffOffs
test [di].exMisc,efConst
jnz @@10
mov cx,ffData+ffOffs
@@10: Invoke PutFixup
pop cx
ret
PutFloatRM endp
PutPrefix proc near
test [di].exMisc,efDS+efBP
jnz @@1
call GetSegment
or al,26h
Chain PutByte
@@1: ret
PutPrefix endp
GetSegment proc near
test [di].exMisc,efDS+efSS+efCS+efES
jnz GetPrefix
mov al,0beh ; mov si,
call LoadSegment
mov ax,0c68eh ; mov ,si
Invoke PutWord
mov al,0
ret
GetSegment endp
GetPrefix proc near
mov al,[di].exMisc
mov ah,18h
test al,efDS
jnz @@1
mov ah,10h
test al,efSS
jnz @@1
mov ah,08h
test al,efCS
jnz @@1
mov ah,0
@@1: mov al,ah
ret
GetPrefix endp
LoadSegment proc near
Invoke PutByte
test [di].exMisc,efConst
jz @@1
push cx dx
mov ax,[di].exSegment
mov bx,[di].exMap
mov cx,ffSegm
xor dx,dx
Invoke PutFixup
pop dx cx
ret
@@1: mov ax,[di].exMap
Chain PutWord
LoadSegment endp
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -