Bona Fide OS Developer
View unanswered posts | View active topics It is currently Thu Mar 28, 2024 5:44 pm



Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
 ASM will not assemble 
Author Message
Post ASM will not assemble
the error is Invalid effective address on this line:
Code:
   mov di,42
   data:
   mov ah,0x0E
  mov al,[bp-di] ;Error
   mov bl,0x0F
   int 0x10
   dec di
   cmp di,0
   jle stoploop
   cmp 0,[bp-di]
   jne data
   stoploop:


Fri Oct 23, 2009 2:36 am

Joined: Sat Jul 25, 2009 11:26 am
Posts: 81
Post Re: ASM will not assemble
There's nothing wrong with your syntax but that's not an effective address.

Code:
mov al, [bp+di] ; good example of an effective address


Stop asking the same questions on every forum you know, you're making the Internet a much more difficult place.

Cheers,
Bogdan


Fri Oct 23, 2009 4:40 am
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: ASM will not assemble
+rep

_________________
Charles Timko
push %esp ;Musings of a computer addict


Fri Oct 23, 2009 11:51 am
Profile WWW
Post Re: ASM will not assemble
i am still getting an invalid effective address
Code:
 mov di,42
 data:
 mov ah,0x0E
 neg di
 mov dh,[bp+di]
 neg di
 mov al,byte [bp+dh]
 mov bl,0x0F
 int 0x10
 dec di
 cmp di,0
 jle stoploop
 neg di
 mov dh,[bp+di]
 neg di
 cmp 0,dh
 jne data
 stoploop:


Fri Oct 23, 2009 12:15 pm
Post Re: ASM will not assemble
now i have new problems with near / far calls
here is the semi working code:
Code:
mov di,42
data:
dec di
mov ah,0x0E
neg di
mov dh,[bp+di]
neg di
mov al,dh
mov bl,0x0F
int 0x10
cmp di,0
jle stoploop
neg di
mov dh,[bp+di]
neg di
cmp dh,0
jne data
stoploop:


Fri Oct 23, 2009 12:36 pm

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: ASM will not assemble
So are you doing your whole OS in ASM?

_________________
Charles Timko
push %esp ;Musings of a computer addict


Fri Oct 23, 2009 6:19 pm
Profile WWW
Post Re: ASM will not assemble
Quote:
So are you doing your whole OS in ASM?

no, this is the child test program


Fri Oct 23, 2009 7:48 pm

Joined: Sat Jul 25, 2009 11:26 am
Posts: 81
Post Re: ASM will not assemble
Your code looks very... random to me. [BP+DH] is again, not an effective address. I think you should take a look at what an effective address is in the Intel manuals. While you're at it, look up the "LEA" instruction (and friends). If you want to do mathematical operations there's the normal way to do it: "ADD, INC, ADC, SUB, SBB, DEC, MUL, IMUL, DIV, IDIV".


Sat Oct 24, 2009 12:58 am
Profile
Post Re: ASM will not assemble
this time i used a C compiler output
Code:
[BITS 16]
   GO:
   push   bp
   mov   bp,sp
   sub   sp,552
   push   si
   ;   
   ;   unsigned char name[32],mode[4],buffer[512];
   ;   name[0]=':';
   ;   
   mov   byte   [bp-40],58
   ;
   ;   name[1]='p';
   ;   
   mov   byte   [bp-39],112
   ;   
   ;   name[2]='a';
   ;   
   mov   byte   [bp-38],97
   ;   
   ;   name[3]='s';
   ;
   mov   byte   [bp-37],115
   ;   
   ;   name[4]='s';
   ;   
   mov   byte   [bp-36],115
   ;   
   ;   name[5]='w';
   ;   
   mov   byte   [bp-35],119
   ;   
   ;   name[6]='o';
   ;   
   mov   byte   [bp-34],111
   ;
   ;   name[7]='r';
   ;   
   mov   byte   [bp-33],114
   ;
   ;   name[8]='d';
   ;   
   mov   byte   [bp-32],100
   ;   
   ;   name[9]= 0 ;
   ;   
   mov   byte   [bp-31],0
   ;   
   ;   mode[0]='r';
   ;
   mov   byte   [bp-4],114
   ;   
   ;   mode[1]= 0 ;
   ;   
   mov   byte   [bp-3],0
   ;   
   ;   FILE far *jar=fopen(name, mode);
   ;
   push   ss
   mov   ax,bp
   sub     ax,4
   push   ax
   push   ss
   mov   ax,bp
   sub     ax,40
   push   ax
   call 0x4000:0x0C4A
   add   sp,16
   mov   word   [bp-6],dx
   mov   word   [bp-8],ax
   ;
   ;   fread(buffer, 1, 512, jar);
   ;
   push   word   [bp-6]
   push   word   [bp-8]
   xor   ax,ax
   mov   dx,512
   push   ax
   push   dx
   xor   ax,ax
   mov   dx,1
   push   ax
   push   dx
   push   ss
   mov   ax,bp
   sub     ax,552
   push   ax
   call   0x4000:0x0DFF
   add   sp,16
   ;
   ;   fclose(jar);
   ;
   push   word   [bp-6]
   push   word   [bp-8]
   call   0x4000:0x0D39
   pop   cx
   pop   cx
   ;
   ;   int i = 0;
   ;
   xor   si,si
   jmp   short @1@114
@1@58:
   ;
   ;   while(i < 512 && buffer[i]){
   ;   _AL = buffer[i];
   ;
   mov   al,byte   [bp+si-552]
   ;
   ;   _AH = 0xE;
   ;
   mov   ah,14
   ;
   ;   _BL = 0xF;
   ;
   mov   bl,15
   ;
   ;   asm {int 10h}
   ;
   int    10h
@1@114:
   cmp   si,512
   jge   short @1@170
   cmp   byte   [bp+si-552],0
   jne   short @1@58
@1@170:
   ;
   ;   }
   ;   }
   ;
   pop   si
   mov   sp,bp
   pop   bp
   retf
   end

almost there


Sat Oct 24, 2009 1:47 am

Joined: Sat Jul 25, 2009 11:26 am
Posts: 81
Post Re: ASM will not assemble
I know a C compiler output when I see it. I also know a bad assembly programmer when I see his/her code. Even if we'd all be using 8-bit CPUs that would still be the crappiest way to set up a string. There are several better solutions:

  • Copy your data from some location instead of setting it character by character. It's not flexible at all.
  • Use words, dwords and qwords to make better use of the bus cycles. Be sure to align your data properly.
  • Combine the above points with dedicated string instructions.
  • Depending on the scenario, you could simply "DB string" somewhere.

You will never be able to write an OS is you skip the learning stage. And you certainly don't learn how to write an OS along the way, as is commonly believed. Take a thorough look at the Intel manuals. Try coding some simple assembly applications first, perhaps even read a book on the subject. That will get you up and going in no time.

Cheers,
Bogdan


Sun Oct 25, 2009 3:01 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.