Can anyone explain why this simple code flips out?
I made this demo just to show you guys this, it's a part of my current project broke off.
I don't want to continue until I can start using the ss and ds reg's again...
And the offset regs...
The only explination I can think of for Demo_1_Bug is because it may be inputting a 32bit value into dx instead of a 16bit one.
So maybe it's inputting the result, the segment, into the offset reg...(the upper word)
That's the only thing I can think off.
I made the demo so it would be small enough to figuer out what was going on and easier to fix if it needs to be fixed.
If these are'nt bugs, then maybe I'm just stupid lol.
Maybe I'm using stuff all wrong...
I'm kinda thinking of moving to straight machine code because of these bugs though, and saying screw asm.
:/
I dn, anyways please check it out
.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; NEO's Bug Demo thingy...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org 0x0100
jmp Init
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Notes:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Segments:
;CS: Code Segment ?, Can't use it for some reason.
;SS: Src Segment Unrealiable, it'll sometimes screw over code that executes before it.
;DS: Dest Segment Unrealiable, it'll sometimes screw over code that executes after it.
;ES: Extra Segment
;Offsets:
;SI: Src Index
;DI: Dest Index
;Both are unreliable, sometimes they will point to the totally wrong offset.
;This prob only happens when they are used in combination with a segment reg, used by themselves as a single instuction they are fine.
;Old notes above are from a current project.
;I felt the need to put together this demo though after a run in with these bugs with no good way of fixing them.
;Even though Demo_1_bug is something I'm not worried about at the moment, I have to wonder how many other functions I could make and have it screw up.
;I've never had any prob with the offset regs before though, this is the only known variatin of it that I know of right now that screws up.
;So it worries me.
;Demo_2, this one worries me even more, it actually pisses me off.
;The whole idea of using ss, ds to me was for src and dest.
;And I used it like that.
;Until I found that a function of mine screwed over when I used either one for the src data.
;I tried using cs but it won't let me, the compilier won't.
;never planned on using that segment reg anyways, maybe someday the es reg, but now...
;So now I'm stuck using a single segment reg (es, the "extra" segment) because the other 2 that are usable I found to be totally unreliable.
;Needless to say, again, it pisses me off...
;About this demo:
;
;Demo_1:
;Shows the normal way to use an int to print a string
;Using ds:dx for the segment and offset, the int's own way of finding the string.
;
;Demo_1_Bug:
;Found by accident.
;I was trying to play it safe by telling dx both the segment and offset of the string.
;Instead of just the offset.
;I forgot that the int had ds setup for the segment location of the string.
;That happened because the Print_String function of mine was a page or so away from the current error reporting function code I had been working on at the time.
;Like I said, was just playing it safe, to safe and it was'nt needed at all.
;mov dx [es:si] (si is the prob)
;[es]:si does'nt work, compilier freaks.
;Does'nt make any sence though, when used correctly it should show the segment -> offset, pointing only to the offset (but then again I dn the internals of this).
;However in this case it's not, the segment is correct, but the offset is not, and it's the segment that caused the prob in the 1st place.
;
;Demo_1_Alt:
;Take the above notes for Demo_1 in hand, and remove the segment from inputing into dx.
;Now the offset is correct, even though the offset was setup the exact say way.
;It works fine, you could do the same by inputting the offset into say ax.
;The idea was t figuer out why the bug showed up in the 1st place though, and to do that I kept the code as identical as possible.
;
;Demo_2_Bug:
;Destroy's the current code and the code before it.
;Meaning, you execute code before it, which has allready ran, then run this code, it somehow goes into the past and destroy's it before it was executed.
;That's the best I can explain it, I would assume it can't go into the past lol..., but it somehow does something like that.
;Note that the src segment was used, src = kill all code before...
;
;Demo_2_Bug_Alt:
;Destroy's the current code and the code after it.
;Note that the dest segment was used, dest = kill all code after...
;
;Demo_2:
;The only way I was able to get this to work correctly the way it was meant to.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Defines:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Code_Segment dw 0x0000
Memory_Segment dw 0x0000
Memory_Offset dw 0x0000
Buffer_32 dd 0x00000000
Generic_Msg db "Hello...", 0x0D, 0x0A, "$"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Functions:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Demo_1_Bug:
mov es, [Code_Segment]
mov si, Generic_Msg
mov dx, [es:si]
mov ds, [Code_Segment]
mov ah, 0x09
dw 0x21CD
ret
Demo_1:
mov dx, Generic_Msg
mov ds, [Code_Segment]
mov ah, 0x09
dw 0x21CD
ret
Demo_1_Alt:
mov si, Generic_Msg
mov dx, si
mov ds, [Code_Segment]
mov ah, 0x09
dw 0x21CD
ret
Demo_2:
mov es, [Memory_Segment]
mov si, [Memory_Offset]
mov eax, [es:si]
mov ds, [Code_Segment]
mov di, Buffer_32
mov [ds:di], eax
ret
Demo_2_Bug:
mov ss, [Memory_Segment]
mov si, [Memory_Offset]
mov eax, [ss:si]
mov ds, [Code_Segment]
mov di, Buffer_32
mov [ds:di], eax
ret
Demo_2_Bug_Alt:
mov ds, [Memory_Segment]
mov si, [Memory_Offset]
mov eax, [ds:si]
mov ds, [Code_Segment]
mov di, Buffer_32
mov [ds:di], eax
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Init:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Init:
mov [Code_Segment], ds
mov [Memory_Segment], 0x0000
mov [Memory_Offset], 0x0000
;Uncomment one of these at a time to see the results.
;call Demo_1
;call Demo_1_Bug
;call Demo_1_Alt
;Uncomment one of these at a time to see the results.
call Demo_1 ;Demo code execution before Demo_2 (Don't comment out) (Note that is was allready executed before the next set of code)
;call Demo_2
;call Demo_2_Bug
;call Demo_2_Bug_Alt
call Demo_1 ;Demo code execution after Demo_2 (Don't comment out)
jmp Exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Exit:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Exit:
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[/code]