作れないものと、作ってもしょうがない物は省いてあります。
16bit版とか、movとか。
誰かバグとかの検証宜しく。
 [ここをクリックすると内容が表示されます]
1月8日1時45分頃:pop関数の不具合を修正。コード: 全て選択
Type STACK
	stack As *DWord
	size As Long
	sp As Long
End Type
Type FLAGS
	c As Byte
	z As Byte
	s As Byte
	o As Byte
End Type
Class ASM
Private
	flags As FLAGS
	stack As STACK
Public
	Sub ASM()
		flags.c=0
		flags.o=0
		flags.s=0
		flags.z=0
		stack.stack=malloc(4)
		stack.size=4
		stack.sp=0
	End Sub
	Sub ~ASM()
		free(stack.stack)
	End Sub
	Sub xchg(ByRef ope1 As DWord,ByRef ope2 As DWord)
		If ope1<>ope2 then
			ope1 Xor=ope2
			ope2 Xor=ope1
			ope1 Xor=ope2
		End If
	End Sub
	Sub push(src As DWord)
		If stack.sp*4>=stack.size then
			stack.size+=4
			stack.stack=realloc(stack.stack,stack.size)
		End If
		stack.stack(stack.sp)=src
		stack.sp++
	End Sub
	Sub pop(ByRef dst As DWord)
		stack.sp--
		dst=stack.stack(stack.sp)
	End Sub
	Sub add(ByRef dst As DWord,src As DWord)
		Dim chk As QWord,chkp As *QWord
		Dim dum1 As QWord,dum2 As QWord
		chkp=VarPtr(chk)+4
		dum1=dst
		dum2=src
		chk=dum1+dum2
		dst=chk As DWord
		flags.c=chkp(0)
		flags.o=chkp(0)
		flags.z=-(chk=0)
		flags.s=(dst And &H80000000)>>31
	End Sub
	Sub adc(ByRef dst As DWord,src As DWord)
		Dim chk As QWord,chkp As *QWord
		Dim dum1 As QWord,dum2 As QWord
		chkp=VarPtr(chk)+4
		dum1=dst
		dum2=src
		chk=dum1+dum2+flags.c
		dst=chk As DWord
		flags.c=chkp(0)
		flags.o=chkp(0)
		flags.z=-(chk=0)
		flags.s=(dst And &H80000000)>>31
	End Sub
	Sub _sub(ByRef dst As DWord,src As DWord)
		If dst<src then flags.c=1
		dst-=src
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
		flags.o=flags.c
	End Sub
	Sub sbb(ByRef dst As DWord,src As DWord)
		Dim dumC As Byte
		If dst<src then dumC=1
		dst-=src+flags.c
		flags.c=dumC
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
		flags.o=flags.c
	End Sub
	Sub neg(ByRef dst As DWord)
		dst=Not dst
		dst++
		flags.c=-(dst<>0)
		flags.s=(dst And &H80000000)>>31
		flags.z=flags.c
		flags.o=0
	End Sub
	Sub _and(ByRef dst As DWord,src As DWord)
		dst And= src
		flags.o=0
		flags.s=(dst And &H80000000)>>31
		flags.z=-(dst=0)
		flags.c=0
	End Sub
	Sub _or(ByRef dst As DWord,src As DWord)
		dst Or= src
		flags.o=0
		flags.s=(dst And &H80000000)>>31
		flags.z=-(dst=0)
		flags.c=0
	End Sub
	Sub _xor(ByRef dst As DWord,src As DWord)
		dst Xor= src
		flags.o=0
		flags.s=(dst And &H80000000)>>31
		flags.z=-(dst=0)
		flags.c=0
	End Sub
	Sub _not(ByRef dst As DWord)
		dst=Not dst
	End Sub
	Sub sal(ByRef dst As DWord,cnt As Byte)
		cnt And=31
		flags.o=-(dst>(&H80000000>>cnt-1))
		dst<<=cnt-1
		flags.c=(dst And &H80000000)>>31
		dst<<1
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
	End Sub
	Sub sar(ByRef dst As DWord,cnt As Byte)
		flags.s=(dst And &H80000000)>>31
		If flags.s=1 then dst=-dst
		cnt And=31
		dst>>=cnt-1
		flags.c=dst And 1
		dst>>1
		flags.z=-(dst=0)
		flags.o=0
		If flags.s=1 then dst=-dst
	End Sub
	Sub shl(ByRef dst As DWord,cnt As Byte)
		cnt And=31
		flags.o=-(dst>(&H80000000>>cnt-1))
		dst<<=cnt-1
		flags.c=(dst And &H80000000)>>31
		dst<<1
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
	End Sub
	Sub shr(ByRef dst As DWord,cnt As Byte)
		cnt And=31
		dst>>=cnt-1
		flags.c=dst And 1
		dst>>1
		flags.z=-(dst=0)
		flags.o=0
		flags.s=(dst And &H80000000)>>31
	End Sub
	Sub rol(ByRef dst As DWord,cnt As Byte)
		Dim dum As DWord
		cnt And=31
		dum=dst>>(32-cnt)
		dst<<=cnt
		dst+=dum
		flags.c=dst And 1
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
		flags.o=-(dum<>0)
	End Sub
	Sub ror(ByRef dst As DWord,cnt As Byte)
		Dim dum As DWord
		cnt And=31
		dum=dst<<(32-cnt)
		dst>>=cnt
		dst+=dum
		flags.c=dst And 1
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
		flags.o=-(dum<>0)
	End Sub
	Sub rcl(ByRef dst As DWord,cnt As Byte)
		Dim dum As DWord
		cnt And=31
		If cnt<>0 then
			dum=(dst>>(33-cnt))+(flags.c<<(cnt-1))
			flags.c=(dst>>(32-cnt)) And 1
		Else
			dum=0
		End If
		dst<<=cnt
		dst+=dum
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
		flags.o=-(dum<>0)
	End Sub
	Sub rcr(ByRef dst As DWord,cnt As Byte)
		Dim dum As DWord
		cnt And=31
		If cnt<>0 then
			dum=(dst<<(33-cnt))+(flags.c<<(32-cnt))
			flags.c=(dst>>(cnt-1)) And 1
		Else
			dum=(dst<<(33-cnt))
		End If
		dst>>=cnt
		dst+=dum
		flags.z=-(dst=0)
		flags.s=(dst And &H80000000)>>31
		flags.o=-(dum<>0)
	End Sub
	Sub stc()
		flags.c=1
	End Sub
	Sub clc()
		flags.c=0
	End Sub
	Sub cmc()
		flags.c=-(flags.c=0)
	End Sub
	Sub pushf()
		Dim varFlag As DWord
		varFlag=flags.c+(flags.z<<6)+(flags.s<<7)+(flags.o<<11)
		push(varFlag)
	End Sub
	Sub popf()
		Dim varFlag As DWord
		pop(varFlag)
		flags.c=varFlag And 1
		flags.z=(varflag And (1<<6))>>6
		flags.s=(varflag And (1<<7))>>7
		flags.o=(varflag And (1<<11))>>11
	End Sub
End Class