assembly strcmp function acting weirdly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: assembly strcmp function acting weirdly

Post by BASICFreak »

I haven't fully read all the replies, but it seems your issues (if it is segment registers) is in the following:

Code: Select all

os_main:
   cli
   cld
   mov ax, 0x7E00
   mov ss, ax
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   mov sp, 0
   sti
A segment of 7E00 translates to a liner address of 7E000
You need a segment of 7E0 to get to liner address 7E00

To calculate 16-bit segment:offset to liner address:
(segment * 16) + offset.

Located in the first two sentences at: http://wiki.osdev.org/Segmentation#Real_mode
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: assembly strcmp function acting weirdly

Post by Combuster »

Well, on that one I say it's because you guys gave me that code. I thought it was valid.
Well, at least you got the free lesson that copy-pasting is a Bad Idea™.

This is because people make assumptions, and different people make different assumptions. If you go mix and match code with contradicting assumptions then the result doesn't work regardless of whether the original parts on their own would.

That said, the FAQ has a nice page called My Bootloader Does Not Work, and things would have been much easier if you had read it in advance. From start your code appeared to have violated the location = segment * 16 + offset rule, and since you provided no chart of where you really wanted to put things every single person here created their own idealistic image of the thing, creating contradicting opinions and even resulting in far more complicated code than necessary.

What you have now probably bears no resemblance to your original work anymore. Go back to square one and start with drawing your memory map, then use that to make sure all the values go to the right places. That way you learn the skill to fix the issues, rather than the skill to try everything and stick with something that will only fail later.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Kirdow
Member
Member
Posts: 35
Joined: Sun Sep 06, 2015 2:20 pm
Libera.chat IRC: Kirdow
Location: Sweden

Re: assembly strcmp function acting weirdly

Post by Kirdow »

Woo. Thanks guys. Now the code works, both the segments and the strcmp. so, last questions:
Because of this topic, it proved that I'm quite a beginner at segments and assembly. So my last question is,
What are some good pdf/websites that I should read though that is really helpful?

Thanks for the help guys

Note: For those who want to know my working code for this problem, here it is.
boot.asm:

Code: Select all

BDA equ 0x0040			; BDA segment
MEM equ 0x0013			; Offset to memsize

ReBoot equ 0x0019
SYSTEM_SERVICES equ 0x0015

DISK_IO equ 0x0013
D_STATUS equ 0x0001
D_READ equ 0x0200
D_WRITE equ 0x0300
GET_DP equ 0x0048

SECTORS equ 0x08 ; sectors to read, change to what you need. sectors = file size (bytes) / 512 (bytes)

jmp 0x7c0:Begin				; For quirky BIOS's so we know CS = 7c0H
;----------------------------
; standard variables
;----------------------------
	
Begin:
	mov ax, BDA		; Points to BIOS DATA AREA
	mov ds, ax
	mov ax, [MEM]	; Get number of 1k pages. Propably 27Fh
	shl ax, 6		; Convert to segment address
	sub ah, 16
	
	cli
	mov ss, ax
	xor sp, sp
	sti
	
	mov ax, cs
	add ax, 32
	mov es, ax
	xor bx, bx		; ES:BX = 0x7c0:0
	
	mov ax, D_READ + SECTORS	; AH = 2, AL = 8 sectors to read
	mov cx, 2					; Begin @ sector 2
	mov dh, 0					; Head 0, probably was that already
	int DISK_IO
	jc Failed
	
	jmp 0:0x7e00		; Jump to second stage.
	
	times 506 - ($-$$) db 90H
	
Failed:
	int 0x16
	int ReBoot
	dw 0xAA55
kernel.asm:

Code: Select all

		BITS 16
	ORG 0x7e00
	
os_main:
	
	cli
	cld
	mov ax, 0x0000
	mov ss, ax
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	mov sp, 0
	sti
	
	; do what you want here
	
times 0x1000 db 0x0 ; this is to make the file exactly 4kb or 8 sectors on disk. If you need another size,
							; change this to want you want but remember to change SECTORS in bootloader
User avatar
JAAman
Member
Member
Posts: 880
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: assembly strcmp function acting weirdly

Post by JAAman »

make sure that you have the intel manuals (there is a link in my signature) -- they are, after all, the ultimate reference for all things x86-CPU

though it doesn't talk a lot about RMode (most of the information assumes you are using the superior PMode or LMode)

I think reading through vol 1 (basic information for assembly programmers) will likely be useful to you (though I can't really be sure, since I haven't even glanced at it in almost 15 years) and volume 2 (3-part instruction set reference) is always handy to have around, and later you will really need to rely on the information available in volume 3 (3 parts, specifically aimed at OS and firmware developers)
Post Reply