Recent Posts

Pages: 1 ... 8 9 [10]
91
Using NASM / Re: can't assemble simple .asm file to .rdf format
« Last post by debs3759 on January 05, 2019, 10:20:29 PM »
It would be easier for someone to help you if you provide some source code that demonstrates the problem.
92
Anyway, I've improved my compiler using the Duktape framework to be able not only to translate single directives from my own programming language into Assembly, but to also be able to translate entire simple programs stored in files. Here is one of the first programs I've written in the first programming language I've made myself:
Code: [Select]
;Advanced example: implementing the permutation algorithm.
AsmStart
    debug=0
macro pushIntToStack x
{
sub esp,4
fld dword [x]
fistp dword [esp]
}
macro pushPointerToStack x
{
sub esp,4
lea ebx,[x]
mov [esp],ebx
}
macro pushStringToStack x
{
sub esp,4
mov dword [esp],x
}
format PE console
entry start

include 'win32a.inc'

section '.text' code executable
start:
jmp enterNumber$
enterNumber db "Enter a whole number (1 - 1'000'000).",10,0
enterNumber$:
pushStringToStack enterNumber
call [printf]
pushPointerToStack original
jmp floatSign$
floatSign db "%f",0
floatSign$:
pushStringToStack floatSign
call [scanf]
jmp permutationString$
permutationString db "The permutations of its digits are:",10,0
permutationString$:
pushStringToStack permutationString
call [printf]
AsmEnd
numberOfDigits:=0
i:=0
While i<10
countDigits[i]:=0
i:=i+1
EndWhile
While original>0
numberOfDigits:= numberOfDigits + 1
lastDigit:= mod( original , 10 )
countDigits[ lastDigit ]:=countDigits( lastDigit ) + 1
original:= (original - lastDigit) / 10
EndWhile
AsmStart
if debug=1
AsmEnd
i:=0
While i<10
subscript:=4*i
AsmStart
fld dword [subscript]
fistp dword [subscript]
mov ebx,[subscript]
pushIntToStack (countDigits+ebx)
pushStringToStack integerSign
call [printf]
AsmEnd
i:=i+1
EndWhile
AsmStart
pushStringToStack newLineString
call [printf]
AsmEnd
AsmStart
end if
AsmEnd
topOfMyStack:=1
myStack[(numberOfDigits+1)]:=0
While topOfMyStack>0
currentNumberOfDigits:=myStack ( topOfMyStack * ( numberOfDigits + 1 ) )
i:=0
While i<currentNumberOfDigits
currentNumber(i):=myStack ( topOfMyStack * ( numberOfDigits + 1 ) + ( i + 1 ) )
i:=i+1
EndWhile
AsmStart
if debug=1
AsmEnd
i:=0
While i<currentNumberOfDigits
subscript:=i*4
AsmStart
fld dword [subscript]
fistp dword [subscript]
mov ebx,[subscript]
pushIntToStack (currentNumber+ebx)
pushStringToStack integerSign
call [printf]
AsmEnd
i:=i+1
EndWhile
AsmStart
pushStringToStack newLineString
call [printf]
AsmEnd
AsmStart
end if
AsmEnd
topOfMyStack:=topOfMyStack-1
If currentNumberOfDigits=numberOfDigits
i:=0
While i<numberOfDigits
subscript:=i*4
AsmStart
fld dword [subscript]
fistp dword [subscript]
mov ebx,[subscript]
pushIntToStack (currentNumber+ebx)
pushStringToStack integerSign
call [printf]
AsmEnd
i:=i+1
EndWhile
AsmStart
pushStringToStack newLineString
call [printf]
AsmEnd
Else
i:=0
While i<10
counter:=0
j:=0
While j<currentNumberOfDigits
If currentNumber(j)=i
counter:=counter+1
EndIf
j:=j+1
EndWhile
If counter<countDigits(i)
topOfMyStack:=topOfMyStack+1
myStack(topOfMyStack*(numberOfDigits+1)):=currentNumberOfDigits+1
j:=0
While j<currentNumberOfDigits
myStack(topOfMyStack*(numberOfDigits+1)+(j+1)):=currentNumber(j)
j:=j+1
EndWhile
myStack (topOfMyStack * (numberOfDigits + 1) + (j + 1) ) := i
EndIf
i:=i+1
EndWhile
EndIf
EndWhile
AsmStart
invoke system,_pause
invoke exit,0

_pause db "PAUSE",0
integerSign db "%d",0
newLineString db 10,0

section '.rdata' readable writable
original dd ?
result dd ?
lastDigit dd ?
numberOfDigits dd ?
countDigits dd 11 dup(?)
subscript dd ?
myStack dd 1000 dup(?)
topOfMyStack dd ?
counter dd ?
i dd ?
currentNumber dd 11 dup(?)
currentNumberOfDigits dd ?
j dd ?


section '.idata' data readable import
library msvcrt,'msvcrt.dll'
import msvcrt,printf,'printf',system,'system',exit,'exit',scanf,'scanf'
AsmEnd
The source code of the compiler, as well as the instructions on how to compile it and use it, can be downloaded here.
So, what do you think about it? Is it worth continuing developing it?
I am also dreaming about making my own LISP-like language, in which you will able to use both S-expressions and infix-expressions (since S-expressions come handy in array and string-manipulation, and infix-expressions come handy in arithmetic expressions), but I am unlikely to have time to develop it in foreseeable future.
93
Using NASM / Re: why i see the text like this
« Last post by encryptor256 on December 31, 2018, 01:18:09 PM »
Hhhehe,  ;D, nice, there is one Rare renegade raider outfit as well. Search in google, and it is what it is - a rare renegade rider outfit. Hard coded text.
94
From the looks of it, I think you're referring to GOT/PLT stuff. Nothing serious about it. It's just how (or where) all your external dependencies (glibc in this case) are stored in memory. This should help explaining
 
95
So by "segment override" that means that the cs register will have whatever was stored in it before replaced with the segment starting address for the "GLIBC_2_2_5" segment?
96
Using NASM / can't assemble simple .asm file to .rdf format
« Last post by johntk on December 24, 2018, 08:32:20 PM »
rdf is badly broken when assembling on windows.  When will this be worked on.  I reported this over 2 years ago.

test.asm
section .text

C:\Compilers\x64\nasm>nasm c:\Users\johnk\OneDrive\Desktop\test.asm -o c:\Users\johnk\OneDrive\Desktop\test.rdf -f rdf
c:\Users\johnk\OneDrive\Desktop\test.asm: panic: rdf segment numbers not allocated as expected (2,4,6)

I may have to get the source code and try to fix it myself.  Any pointers on where to look in the code to fix this problem.
John
97
Programming with NASM / Re: My write_file function does not work
« Last post by yoran on December 23, 2018, 03:55:56 PM »
Already fixed it myself, thanks
98
Programming with NASM / My write_file function does not work
« Last post by yoran on December 23, 2018, 02:29:18 PM »
My write_file function does not work, everytime it copies far to much onto the disk from RAM or just nothing. Also when I reboot the OS it corrupts the file.
99
Ahhh, I've been thinking I should have tried to explain that better, although I do NOT claim to know C! The C Standard Library contains open(). read(), write(). etc.  - equivalent (?) to the system calls you're probably used to. It also includes fopen(), fread(), etc. If you learn C "from the book", it probably tells you to use fread(), etc. and may not even mention that the other versions exist. The difference is that the "f" versions are "buffered I/O".  These use a "different stdin" (etc.) than the small integer "STDIN" you'd use for system calls. This "stdin" (I think) is the address of a structure which knows where the actual buffer is and the current position in the buffer 0 as well as STDIN=0, I suppose. If you're not aware that you've asked for buffered I/O, the results may not be what you expect.
"cs" is a segment register, but in this case it's a segment override - the address of "stdin" is with respect to section .text rather than .data or .bss. "fgets" itself would be in .text, although the address of it might be found elsewhere(?). I think IDA is adding that (and the underscore on "fgets). I don't think you'd need them if you were writing the code yourself.

Best,
Frank

100
Frank nice to hear from you,

thanks for giving some clarification. Specifically what is the cs:GLIBC_2_2_5 doing... cs is a segment register correct? and LibC is the "C library of functions" so I'm assuming that that points to some offset in the .bss or .data section that has the "fgets" function call? And loading that offset into rdx? For 64- bit the 3rd arg is put into rdx register, so in this case that would be the "FILE *stream" argument for fgets

Code: [Select]
char *fgets(char *s, int size, FILE *stream)
Pages: 1 ... 8 9 [10]