real mode dos assembly trouble

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

Well how it is goin', Zacariaz? Did the helloworld example compiled successfully? :)

Note: Do not try to attempt to write registers values on the screen using ASM for now, try something easier like hello world program that asks for a keyboard input, and then it will echo back with the string :) If you need help, just ask ;)

Regards
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

inflater wrote:Well how it is goin', Zacariaz? Did the helloworld example compiled successfully? :)

Note: Do not try to attempt to write registers values on the screen using ASM for now, try something easier like hello world program that asks for a keyboard input, and then it will echo back with the string :) If you need help, just ask ;)

Regards
inflater
Hello world is the easiest thing in the world and works perfectly.
Remember that im not stupid, actually im fairly intelligent, however, the structure can be difficult, especially in ASM where the structure varies from different assemblers. just condider intel vs. AT&T suntax...

I have always loved the step-step-by-concept of ASM, but never really got started.

I was actually thinking about constuction a program which prints every prime number from 0x0 - 0xffff. The structure of the program should be too difficult, however i would need some sort of searchable stack or vector or simular, and that is... well im thinking about that ;)

Com to think about it i believe i asked a related question with some example code at some time at programmersheaven... ill post a link if i find it and it doesnt imbaress me too much ;)
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

Your code seems fine for me... ;)
Anyways, you can use INT 20h instead of END. ;) What assembler are you using?
Overflow handling? I suggest hooking a custom ISR to INT 0 (I highly recommend to read on DOS's INT 21h and to not use BIOS = if you exit from your program, you would run some GUI program that caused overflow, and it will trigger INT 0... and you realize that your INT0 ISR had a "jmp ExitFromIsrToMainProgram"... ehh, the result can be highly predictable :lol:). :D If you would use BIOS, MS-BOSS wouldn't have idea that the INT0 has changed... ;)

Yes you do not need to MOV EDX,0, if you are changing the EDX right after it. ;) Its quite simple, but harder to tell -> if you MOVe something to a register, it will automatically erase everything that is stored on the destination (register), and replace it with contents specified as the second operand (source, in the INTEL syntax). But if you have some high number stored in EDX (full 32bit number, like 0FFFFFFFFh), and you would just do MOV DX, 5, I think the CPU will leave the 32bit part "as it is"... Correct me if this is wrong please.

By the way, 0x2 is the same as 2, and 0x0 is the same as XORing the same register with the same (it is faster as you already know, but noticeable maybe only on eerly 8086/80186/V30 etc. :D), or 0x0 = 0 simply. :) Save two bytes of "0x" in your asm code :lol:

JNE means "jump if not eqal", you are right :), so if CMP EDX,0 ; JNE NOTPRIME would jump to label NOTPRIME if EDX is not 0. I think you already know that :)

Regards
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

My DIV explanation:

To divide 16 by 4:

mov ax,10h
mov bx,4
div bx

; now in AX there should be 4 ;)
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

lets see... the first post is from 11 Jan 2007, so its not so old as i thought, still i only posted it to give an example to what i was considering doing as one of my first programs.
Anyway thanks for the tips and stuff ;)
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

inflater wrote:My DIV explanation:

To divide 16 by 4:

mov ax,10h
mov bx,4
div bx

; now in AX there should be 4 ;)
yes, and bx should hold the remainder right? = 0;
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

yes, and bx should hold the remainder right? = 0;
...and DX should hold the remainder :D

Regards
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

oh well, bx, dx, zx81 (yes i have one of those), its easy to get confused ;)
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

You have ZX Spectrum 81? :shock:... in times of USSR and Czechoslovakia (<1991), you know how the computer (ordinary 286 :lol:) was expensive? :D I had the only microcomputer Didaktik in my house [along with 1997], and it was borrowed too :) Ah, the good old days :P

Regards
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

I got it from a family mamber of mine, i actually never did learn how to use it. but i do have those 64kb of extra ram ;) Maybe i should write an os for that? lol
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

A snippet of code from mikeos handbook:

Code: Select all

	BITS 16

start:
	mov ax, 07C0h		; Set up 4K stack space after this bootloader
	add ax, 512
	mov ss, ax
	mov sp, 4096

	mov ax, 07C0h		; Set data segment to where we're loaded
	mov ds, ax
makes sence but wouldnt this be the same yet one intruction shorter yet give the same result?:

Code: Select all

	BITS 16

start:
	mov ax, 07C0h		; Set data segment to where we're loaded
	mov ds, ax
	add ax, 512		; Set up 4K stack space after this bootloader
	mov ss, ax
	mov sp, 4096
allso i wouldnt be surprised if ADD uses more clockcycles than mov, in which case it could be a god thing writing:
mov ax,07C0h
instead of
add ax,512

are all this just wrong assumtions?

nb: im not critisising the handbook here, i just wonder if im right...
Last edited by Zacariaz on Wed Sep 26, 2007 12:50 pm, edited 1 time in total.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Maybe it's one of those let the code document itself things.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

Im really just interested in if im right or not, and to tell someone of, cause im definently not qualified for that...
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Yes both code items you posted will have same results. One just looks nicer.
Post Reply