View previous topic :: View next topic | |||||||
Author | Message | ||||||
---|---|---|---|---|---|---|---|
mm-motm Tux’s lil’ helper Joined: 27 Oct 2003 |
|
||||||
Back to top |
|
||||||
TNorthover Guru Joined: 25 Jan 2004 |
|
||||||
Back to top |
|
||||||
hjnenc Veteran Joined: 15 Aug 2004 |
|
||||||
Back to top |
|
||||||
mm-motm Tux’s lil’ helper Joined: 27 Oct 2003 |
|
||||||
Back to top |
|
||||||
mm-motm Tux’s lil’ helper Joined: 27 Oct 2003 |
|
||||||
Back to top |
|
||||||
TNorthover Guru Joined: 25 Jan 2004 |
|
||||||
Back to top |
|
||||||
hjnenc Veteran Joined: 15 Aug 2004 |
|
||||||
Back to top |
|
||||||
TNorthover Guru Joined: 25 Jan 2004 |
|
||||||
Back to top |
|
||||||
hjnenc Veteran Joined: 15 Aug 2004 |
|
||||||
Back to top |
|
||||||
|
You cannot post new topics in this forum |
Chapter 13: Troubleshooting
This chapter describes some of the common problems that users have been
known to encounter with NASM, and answers them. If you think you have found
a bug in NASM, please see section
E.2.
13.1 Common Problems
13.1.1 NASM Generates Inefficient Code
We sometimes get `bug’ reports about NASM generating inefficient, or
even `wrong’, code on instructions such as ADD ESP,8
. This is
a deliberate design feature, connected to predictability of output: NASM,
on seeing ADD ESP,8
, will generate the form of the instruction
which leaves room for a 32-bit offset. You need to code
ADD ESP,BYTE 8
if you want the space-efficient form of the
instruction. This isn’t a bug, it’s user error: if you prefer to have NASM
produce the more efficient code automatically enable optimization with the
-O
option (see section
2.1.24).
13.1.2 My Jumps are Out of Range
Similarly, people complain that when they issue conditional jumps (which
are SHORT
by default) that try to jump too far, NASM reports
`short jump out of range’ instead of making the jumps longer.
This, again, is partly a predictability issue, but in fact has a more
practical reason as well. NASM has no means of being told what type of
processor the code it is generating will be run on; so it cannot decide for
itself that it should generate Jcc NEAR
type instructions,
because it doesn’t know that it’s working for a 386 or above.
Alternatively, it could replace the out-of-range short JNE
instruction with a very short JE
instruction that jumps over a
JMP NEAR
; this is a sensible solution for processors below a
386, but hardly efficient on processors which have good branch prediction
and could have used JNE NEAR
instead. So, once again,
it’s up to the user, not the assembler, to decide what instructions should
be generated. See section
2.1.24.
13.1.3 ORG
Doesn’t Work
People writing boot sector programs in the bin
format often
complain that ORG
doesn’t work the way they’d like: in order
to place the 0xAA55
signature word at the end of a 512-byte
boot sector, people who are used to MASM tend to code
ORG 0 ; some boot sector code ORG 510 DW 0xAA55
This is not the intended use of the ORG
directive in NASM,
and will not work. The correct way to solve this problem in NASM is to use
the TIMES
directive, like this:
ORG 0 ; some boot sector code TIMES 510-($-$$) DB 0 DW 0xAA55
The TIMES
directive will insert exactly enough zero bytes
into the output to move the assembly point up to 510. This method also has
the advantage that if you accidentally fill your boot sector too full, NASM
will catch the problem at assembly time and report it, so you won’t end up
with a boot sector that you have to disassemble to find out what’s wrong
with it.
13.1.4 TIMES
Doesn’t Work
The other common problem with the above code is people who write the
TIMES
line as
TIMES 510-$ DB 0
by reasoning that $
should be a pure number, just like 510,
so the difference between them is also a pure number and can happily be fed
to TIMES
.
NASM is a modular assembler: the various component parts are
designed to be easily separable for re-use, so they don’t exchange
information unnecessarily. In consequence, the bin
output
format, even though it has been told by the ORG
directive that
the .text
section should start at 0, does not pass that
information back to the expression evaluator. So from the evaluator’s point
of view, $
isn’t a pure number: it’s an offset from a section
base. Therefore the difference between $
and 510 is also not a
pure number, but involves a section base. Values involving section bases
cannot be passed as arguments to TIMES
.
The solution, as in the previous section, is to code the
TIMES
line in the form
TIMES 510-($-$$) DB 0
in which $
and $$
are offsets from the same
section base, and so their difference is a pure number. This will solve the
problem and generate sensible code.
-
I am a *budding* programmer(read: ignorant noob), and I have a question.
I have not been able to compile ANYTHING with ubuntu.
The errors I get always seem to be different, and I don’t think this is a library linking problem. I heard about gcc 4.0 not being able to compile some old things.
So, my simple question is, will installing older versions of gcc(eg,3.4 & etc)
solve some of these problems? I know it won’t solve all problems, but could it possibly have an effect?Forgive my ignorance.
GUNZIP!! BUNZIP TOO!!!«I may not understand what I’m installing, but that’s not my job. I just need to click Next, Next, Finish here so I can walk to the next system and repeat the process»
— Anonymous NT Admin
-
Re: A simple question
First of all, make sure you have the package build-essential installed. Second, what kind of errors are you getting? A few specific examples might be helpful. I doubt that using an older compiler would be helpful.
-
Re: A simple question
Originally Posted by rmjokers
First of all, make sure you have the package build-essential installed. Second, what kind of errors are you getting? A few specific examples might be helpful. I doubt that using an older compiler would be helpful.
I did that, thanks. While I was at it I took a look at the Readme of the current program I am trying to compile
(it’s Gens for Linux, a Sega Genesis&etc emulator) and found a list of packages that it required to compile correctly
(one of those was gcc 2.95, and installing it and using it to compile actually did help).That helped, but this program requires the «nasm» x86 assembly compiler package to build correctly. I installed it as previously mentioned, but I got these errors when nasm was called during compilation:
nasm -D__GCC2 -f elf -O3 vdp_rend.asm -ovdp_rend.o
vdp_rend.asm:2089: error: short jump is out of range
vdp_rend.asm:2112: error: short jump is out of range
vdp_rend.asm:2116: error: short jump is out of range
vdp_rend.asm:2119: error: short jump is out of range
vdp_rend.asm:2126: error: short jump is out of range
vdp_rend.asm:2130: error: short jump is out of range
vdp_rend.asm:2133: error: short jump is out of range
vdp_rend.asm:2155: error: short jump is out of range
vdp_rend.asm:2159: error: short jump is out of range
vdp_rend.asm:2162: error: short jump is out of range
vdp_rend.asm:2169: error: short jump is out of range
vdp_rend.asm:2173: error: short jump is out of range
vdp_rend.asm:2176: error: short jump is out of range
vdp_rend.asm:2195: error: short jump is out of range……&etc, with this line at the end:
vdp_rend.asm:2260: error: phase error detected at end of assembly.
make: *** [vdp_rend.o] Error 1This means nothing to me.
Gens for Linux is a bit buggy still, so this may be a coding error.
If so, forgive me for taking all this forum space up.Last edited by phanboy_iv; November 8th, 2005 at 11:39 PM.
GUNZIP!! BUNZIP TOO!!!«I may not understand what I’m installing, but that’s not my job. I just need to click Next, Next, Finish here so I can walk to the next system and repeat the process»
— Anonymous NT Admin
-
Re: A simple question
I too am having the same exact problem compiling gens. I am using gcc 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2) and nasm 0.98.38. I was getting other errors such as «‘GTK_FILE_SELECTION’ was not declared in this scope» and «‘gtk_file_selection_get_filename’ was not declared in this scope», but I got past that by removing the GTK_DISABLE_DEPRECATED flag from the makefile. Any help with this would be appreciated since I have been unable to find any other good sega emulator with a gui.
P.S. I’m using ubuntu 7.10
View unanswered posts | View active topics
Author | Message | ||||||
---|---|---|---|---|---|---|---|
Post subject: Re: 512-byte OS Contest
|
|||||||
|
Here’s zeroflag’s entry, a limited basic-like interactive interpretive language! @inflater: I never got an email from you
Solar wrote: It keeps stunning me how friendly we — as a community — are towards people who start programming «their first OS» who don’t even have a solid understanding of pointers, their compiler, or how a OS is structured. I wish I could add more tex |
||||||
Top |
|
||||||
Dex |
Post subject: Re: 512-byte OS Contest
|
|
I will wait a day or two, than i will take screenshots of the entrys and post a link. |
Top |
|
Troy Martin |
Post subject: Re: 512-byte OS Contest
|
||
|
My entry, |)emOS is complete, it’s not much, just a little shell with 1-letter commands in 512-bytes with a register dump tool for fun Commands: e (echo), d (dump), h (random number generator), ? (help).
Solar wrote: It keeps stunning me how friendly we — as a community — are towards people who start programming «their first OS» who don’t even have a solid understanding of pointers, their compiler, or how a OS is structured. I wish I could add more tex |
||
Top |
|
||
Troy Martin |
Post subject: Re: 512-byte OS Contest
|
||
|
Zenith’s entry, a snake game, is here!
Solar wrote: It keeps stunning me how friendly we — as a community — are towards people who start programming «their first OS» who don’t even have a solid understanding of pointers, their compiler, or how a OS is structured. I wish I could add more tex |
||
Top |
|
||
geppy |
Post subject: Re: 512-byte OS Contest
|
|
Every single person here tries to put in one single feature.Could you explain how come is it an Operating System and whats the point of slow running Snake game without any features or effects (comparing to SSE version in Protected Mode). |
Top |
|
Troy Martin |
Post subject: Re: 512-byte OS Contest
|
||
|
Cause it’s fun. 01000101’s entry is ready, a «half-baked Fallout 3 terminal interface clone!»
Solar wrote: It keeps stunning me how friendly we — as a community — are towards people who start programming «their first OS» who don’t even have a solid understanding of pointers, their compiler, or how a OS is structured. I wish I could add more tex |
||
Top |
|
||
inflater |
Post subject: Re: 512-byte OS Contest
|
|
//EDIT: Attention, please close your bids. 0:00 hours remaining Deadline! Now it’s time to check. Who’s up for testing? |
Top |
|
eddyb |
Post subject: Re: 512-byte OS Contest
|
|
Tested Fallout3. EDIT: |
Top |
|
Troy Martin |
Post subject: Re: 512-byte OS Contest
|
|
Sorry for the delay but we’re having serious poll issues (options doubling, some disappearing) and we need to find someone who can host a poll for us. Solar wrote: It keeps stunning me how friendly we — as a community — are towards people who start programming «their first OS» who don’t even have a solid understanding of pointers, their compiler, or how a OS is structured. I wish I could add more tex |
Top |
|
inflater |
Post subject: Re: 512-byte OS Contest
|
|
Mine results: |)emos: compiling error, Code: D:OSdev512BYTE>nasm -o boot.bin demos.asm This can be fixed by either moving the labels onto the beginning of the file and JMP START, or just using the NEAR suffix (and setting CPU mode to 386). Please explain, how it’s useful to have section .bss, private variables and labels, and the «jmp short» suffix, Troy? After all, it works. |
Top |
|
chezzestix |
Post subject: Re: 512-byte OS Contest
|
|
Troy Martin wrote: Sorry for the delay but we’re having serious poll issues (options doubling, some disappearing) and we need to find someone who can host a poll for us. Not sure what you need but if you have the page and all you need is space on a webserver then I can help you out there. I extensively tested Snake512. Got up to a score of 94 at one point. Downfall: Not a bad game otherwise. |
Top |
|
01000101 |
Post subject: Re: 512-byte OS Contest
|
|
shiner wrote: Tested Fallout3. haha yeah, I forgot to give the password, but it’s pretty obvious if you check out the source. I apologize for my half-baked entry as I stopped working on it a few days ago due to some new things with my own OS. The point is just to look similar to that of the Fallout 3 terminals, nothing more, nothing less. I originally wanted to do some 64-bit stuff, but I couldn’t find any ‘features’ that would be worth it and could still fit in the remaining space after paging/double-sized gdt/ and just the rest of the init code. Maybe next time I’ll think a little harder about things to do in 64-bit. |
Top |
|
mrnoob |
Post subject: Re: 512-byte OS Contest
|
|
ah well, i got caught up in other things and couldnt do my entry in time. I was going to make an interactive debugger, from lack of ideas. |
Top |
|
Troy Martin |
Post subject: Re: 512-byte OS Contest
|
|
inflater wrote: Please explain, how it’s useful to have section .bss, private variables and labels, and the «jmp short» suffix, Troy? TLDR version: It’s my coding style and asm optimizations. Long(er) version: Solar wrote: It keeps stunning me how friendly we — as a community — are towards people who start programming «their first OS» who don’t even have a solid understanding of pointers, their compiler, or how a OS is structured. I wish I could add more tex |
Top |
|
cippo |
Post subject: Re: 512-byte OS Contest
|
||
|
Oops, was I too late? Guess I misunderstood your «Entries must be in by Jan. 6th, 2009 at midnight PST (GMT-8)». Thought you meant Jan 6. 23:59:59+ 1 sec. Ohwell, I’ll just dump it here anyway. It’s a vi-like editor and a brainfuck interpreter. It supports moving around with h, j, k and l, opening lines above and below with O and o and inserting text with i. To interpret the file you’ve written press I (that is capital i). All the commands above should be inserted in command mode (you see which mode you’re in in the lower left corner, C = command, I = input). And as always esc takes you back from input to command. Cheers,
|
||
Top |
|
||
Who is online |
Users browsing this forum: rdos and 5 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 |
@Wayne:
The jump is out of range here because the debugger inserts
extra stuff — compiles fine with debugger disabled.
It compiles also if you use DisableDebugger+EnableDebugger
around your procedure/asm-code, so the debugger doesnt
insert extra stuff.
Another thing:
I dont think ReplaceString(A$, » «, Chr(0), 1, 1) is right. PureBasic uses
ASCIIZ-Strings, so ‘0’ is not a valid char.
Use allocated memory for buffers/data: sTmpData = AllocateMemory(1,1000)
Still doesnt work with this modifications, app just closes in your
function Compress().
You ask why? Its easy, your code:
Code: Select all
Procedure.l Compress(ptrInData.l, LenInData.l, ptrOutData.l, ptrTmpData.l)
PUSHAD
PUSH ptrTmpData
PUSH LenInData
PUSH ptrInData
PUSH ptrOutData
CALL l_cstart
JMP l_cend
is translated to:
Code: Select all
; PUSHAD
PUSHAD
; PUSH ptrTmpData
PUSH dword [esp+12]
; PUSH LenInData
PUSH dword [esp+4]
; PUSH ptrInData
PUSH dword [esp]
; PUSH ptrOutData
PUSH dword [esp+8]
; !CALL l_cstart
CALL l_cstart
; !JMP l_cend
JMP l_cend
After your PUSHAD, the stack has changed. As you can see,
PB doesnt update the internal stack calculation on PUSHAD
and still assumes that the 4 arguments are in [ESP] — [ESP+12].
What PB pushes here are the registers you pushed with PUSHAD
before.
The 2nd Problem: PB also doesnt update the internal Stack-Counter
after every ‘PUSH variable’ (see above).
I tried to correct this problem with directASM, but there is still
an Error in the code. I checked also your PUSH/POP pairs and it
seems to be OK:
Code: Select all
OnErrorGoto(?Error)
DisableDebugger
Procedure.l Compress(ptrInData.l, LenInData.l, ptrOutData.l, ptrTmpData.l)
!PUSHAD
; PUSH ptrTmpData
!PUSH dword [esp+12 + 32 ]
; PUSH LenInData
!PUSH dword [esp+4 + 32 + 4]
; PUSH ptrInData
!PUSH dword [esp + 32 + 8]
; PUSH ptrOutData
!PUSH dword [esp+8 + 32 + 12]
!CALL l_cstart
!JMP l_cend
CStart:
!SUB edx, edx
!XCHG eax, edx
!PUSHAD
!MOV ebp, esp
!AND ecx, eax
!MOV edi, [ebp+0x30]
!CLD
!MOV ch, 0x40
!PUSH edi
!REP stosd
!SUB edx, 0x2864E25C
!MOV esi, [ebp+0x28]
!JNZ l_pack0
!DEC edx
pack0:
!PUSH ecx
!SUB ax, 0x0AEB6
!MOV edi, [ebp+0x24]
!POP ebx
!stosw
!XCHG eax, edx
!POP ebp
!stosd
!PUSH edi
!XCHG eax, edx
!PUSH esp
pack1:
!TEST cl, 7
!lodsb
!JNZ l_pack3
!XCHG edx, [esp]
!ADC ah, dl
!POP edx
!XCHG edi, [esp]
!ROR edx, 1
!MOV [edi], ah
!JC l_pack2
!XOR edx, 0x2C047C3E
pack2:
!POP edi
!MOV ah, 0x0FF
!PUSH edi
!XOR edx, 0x76C52B8D
!INC edi
!PUSH edx
pack3:
!CMP al, [ebx+ebp]
!JZ l_pack5
!ROR edx, 1
!MOV [ebx+ebp], al
!JNC l_pack4
!XOR edx, 0x2C047C3E
pack4:
!MOV bh, al
!XOR edx, 0x5AC157B3
!ADC al, dl
!stosb
!MOV al, bh
!STC
pack5:
!INC ecx
!MOV bh, bl
!RCL ah, 1
!CMP ecx, [esp+0x34]
!MOV bl, al
!JC l_pack1
!ROR ah, cl
!POP ebx
!ADD ah, bl
!POP esi
!MOV ebp, esp
!SUB edi, [ebp+0x24]
!MOV [ebp+0x14], edx
!XCHG ah, [esi]
!ADD [ebp+0x1C], edi
!POPAD
!RET 0x10
CEnd:
!POPAD
EndProcedure
EnableDebugger
;Dim sInData AS STRING, sOutData AS STRING, sTmpData AS STRING * 65535, OutSize AS DWORD
sTmpData.s = Space(1000)
sTmpData = ReplaceString(sTmpData, " ", Chr(0), 1, 1)
;sTmpData = AllocateMemory(1,1000)
;// Data to compress
sInData.s = "testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting"
;// Compress it ...
sOutData.s = Space(Len(sInData))
sOutData.s = ReplaceString(sOutData, " ", Chr(0), 1, 1)
OutSize.l = Compress(@sInData, Len(sInData), @sOutData, @sTmpData)
If OutSize > Len(sInData)
Debug "Unable to compress this data (probably not enough repetition)."
;End
EndIf
A$ = "Original size = " + StrU(Len(sInData), #LONG) + " bytes"
B$ = "Compressed size = " + StrU(OutSize,#LONG) + " bytes"
MessageRequester("INFO",A$+Chr(13)+B$)
End
Error:
MessageRequester("FATAL ERROR !",GetErrorDescription(),#MB_ICONERROR)
End
You should check now if all your stack calculation is correct
(!MOV esi, [ebp+0x28] and all this), there is a protection fault
somewhere (write/read to/from wrong address).