Hey all,
I was reading a book by Paul Carter entitled "PC Assembly Language" when I reached my first program, I was rather excited until I came upon a problem
the book utilizes NASM and DJGPP to create the assembly code however I am using Flat Assembler, observe the book's "First Program" below
Now onto my question how would I port this to FASM (if its possible) and is there a constant set of instructions needed to do this.
Here is the Example instructions with all various forms: http://www.drpaulcarter.com/pcasm/
at the bottom of the provided link is the example code.
Thanks,
v0rtex.
I was reading a book by Paul Carter entitled "PC Assembly Language" when I reached my first program, I was rather excited until I came upon a problem
the book utilizes NASM and DJGPP to create the assembly code however I am using Flat Assembler, observe the book's "First Program" below
%include "asm_io.inc"
segment .data
prompt1 db "Enter a number: " , 0
prompt2 db "Enter another number: " , 0
outmsg1 db "You entered " , 0
outmsg2 db " and ", 0
outmsg3 db ", the sum of these is ", 0
segment .bss
input1 resd1
input2 resd1
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha
mov eax, prompt1
call print_string
call read_int
mov , eax
mov eax, prompt2
call print_string
call read_int
mov ,eax
mov eax,
add eax,
call print_int
mov eax, outmsg2
call print_string
mov eax,
call print_int
mov eax, outmsg3
call print_string
mov eax, ebx
call print_int
call print_nl
popa
mov eax,0
leave
ret
Now onto my question how would I port this to FASM (if its possible) and is there a constant set of instructions needed to do this.
Here is the Example instructions with all various forms: http://www.drpaulcarter.com/pcasm/
at the bottom of the provided link is the example code.
Thanks,
v0rtex.
format elf
include "asm_io.inc"
section '.data'
prompt1 db "Enter a number: " , 0
prompt2 db "Enter another number: " , 0
outmsg1 db "You entered " , 0
outmsg2 db " and ", 0
outmsg3 db ", the sum of these is ", 0
section '.bss' writable
input1 resd1
input2 resd1
section '.text' executable
public _asm_main
_asm_main:
enter 0,0
pusha
mov eax, prompt1
call print_string
call read_int
mov , eax
mov eax, prompt2
call print_string
call read_int
mov ,eax
mov eax,
add eax,
mov ebx, eax
dump_regs 1
dump_mem 2, outmsg1, 1
mov eax, outmsg1
call print_string
mov eax,
call print_int
mov eax, outmsg2
call print_string
mov eax,
call print_int
mov eax, outmsg3
call print_string
mov eax, ebx
call print_int
call print_nl
popa
mov eax,0
leave
ret
But of course the include file will be missing. I've assumed that you intended to create an ELF object file, if you need this for Windows perhaps the linker won't support this format so you'll have to use "MS COFF" or "COFF" format instead (check the manual).I have the same problem too, could someone help me?
V0rtex mentions DJGPP. DJGPP uses "COFF" (Common Object File Format) for it's linkable object files. Windows also uses COFF... but it's a slightly different version of COFF. If you were using Nasm, you would specify the output format on the command line: "-f coff" for DJGPP COFF, and "-f win32" for MS-COFF. Fasm specifies the output format in the source, so this would have to be added to Dr. Carter's examples, as LocoDelAssembly shows.
Unless I'm mistaken, Fasm will produce either an executable format directly, or a linkable object format. Dr. Carter's system requires a linkable object file, since he links with C libraries in order to be "portable". Portability doesn't happen by magic, it requires some thought (this is true even with C, regardless of what it says in the glossy brochure!). I'm thinking "format elfobj" (I'm not sure how Fasm spells it) might be correct, rather than "format elf"(?).
There's another subtle difference...
Nasm:
Note the space between "resd" and "1"! The posted code is not quite correct, IMO.
Unless I'm mistaken, Fasm uses...
There may be other small differences, but the actual CPU instructions are the same (I'm pretty sure). These small differences would have to be applied to the example files, "asm_io.inc", and "asm_io.asm"... I think "driver.c" would be okay without any changes(?).
Although the differences between Nasm and Fasm are small, they're enough so that it "won't work" if it's not done right. Beginners, struggling to learn assembly language, don't need any "extra complications"! It might be worth your while to switch to Nasm, at least "for the duration" of working through Dr. Carter's book and examples.
http://www.nasm.us
I think the download page is working, although the Forum is down. (if SpooK or synfire or p1ranha know anything about that, clue me in - I can't even log in to Peter's machine to check mail at the moment. fbkotler at myfairpoint dot net - always happy to talk about assembly language!)
But I know how asm-folk are - we're a pretty stubborn lot! If you wanna use Fasm, you wanna use Fasm! I'm a "devout Nasmist", myself (sounds nicer than "Nasm bigot", but it means the same :) ) I'd probably be using Fasm if I hadn't already been "hooked" on Nasm when Fasm came out! Nice assembler - Tomasz is doing a terrific job! But I'm not that familiar with the details of it. I'd be glad to conspire with anyone familiar with Fasm to get Dr. Carter's examples working, if there's interest in it. (heck, I'm even attempting to write some Gas code lately - boy, do I make a lot of mistakes!)...
Fasm has a nice forum. I don't check it often. There may be some information on this subject already. No harm "reinventing the wheel" - if we didn't, they'd still be chipped out of granite and have wooden axels - but duplicating work already done is foolish. Some "Fasmist" should check this!
Best,
Frank
Unless I'm mistaken, Fasm will produce either an executable format directly, or a linkable object format. Dr. Carter's system requires a linkable object file, since he links with C libraries in order to be "portable". Portability doesn't happen by magic, it requires some thought (this is true even with C, regardless of what it says in the glossy brochure!). I'm thinking "format elfobj" (I'm not sure how Fasm spells it) might be correct, rather than "format elf"(?).
There's another subtle difference...
Nasm:
section .bss
input1 resd 1
Note the space between "resd" and "1"! The posted code is not quite correct, IMO.
Unless I'm mistaken, Fasm uses...
section '.bss' writable
input1 rd 1
There may be other small differences, but the actual CPU instructions are the same (I'm pretty sure). These small differences would have to be applied to the example files, "asm_io.inc", and "asm_io.asm"... I think "driver.c" would be okay without any changes(?).
Although the differences between Nasm and Fasm are small, they're enough so that it "won't work" if it's not done right. Beginners, struggling to learn assembly language, don't need any "extra complications"! It might be worth your while to switch to Nasm, at least "for the duration" of working through Dr. Carter's book and examples.
http://www.nasm.us
I think the download page is working, although the Forum is down. (if SpooK or synfire or p1ranha know anything about that, clue me in - I can't even log in to Peter's machine to check mail at the moment. fbkotler at myfairpoint dot net - always happy to talk about assembly language!)
But I know how asm-folk are - we're a pretty stubborn lot! If you wanna use Fasm, you wanna use Fasm! I'm a "devout Nasmist", myself (sounds nicer than "Nasm bigot", but it means the same :) ) I'd probably be using Fasm if I hadn't already been "hooked" on Nasm when Fasm came out! Nice assembler - Tomasz is doing a terrific job! But I'm not that familiar with the details of it. I'd be glad to conspire with anyone familiar with Fasm to get Dr. Carter's examples working, if there's interest in it. (heck, I'm even attempting to write some Gas code lately - boy, do I make a lot of mistakes!)...
Fasm has a nice forum. I don't check it often. There may be some information on this subject already. No harm "reinventing the wheel" - if we didn't, they'd still be chipped out of granite and have wooden axels - but duplicating work already done is foolish. Some "Fasmist" should check this!
Best,
Frank