Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Using NASM / Re: Error message on windows: fatal: unable to open output file (?)
« Last post by debs3759 on November 20, 2020, 06:06:52 PM »
I'm not sure, but it could be because you are trying to output it under "Program Files". Windows can be quite strict about where you can write files, and Program Files is possibly a protected operating system directory.
22
Using NASM / Error message on windows: fatal: unable to open output file (?)
« Last post by gomi on November 20, 2020, 04:47:09 PM »
Hello, I am interested in assembly programs. I want to make simple boot.asm file and run it in qemu. I made asm file run nasm in order to compile to bin on win10x64 with command " nasm boot.asm -f bin -o boot.bin " Note that my nasm was came from installer so it is located in " C:\Program Files\NASM> " so I put my boot.asm inside it too. However, I got fatal: " unable to open output file boot.bin "

Yes I know that I would do it on linux but somehow I have to do this on windows10x64.

Thank you very much for any help.
23
Using NASM / Re: Linux or DOS
« Last post by Frank Kotler on November 19, 2020, 07:44:03 PM »
Thanks Debs

Thanks Frederico

Many eyes make fewer bugs!

Best,
Frank

24
Using NASM / Re: Suboptimal code generation?
« Last post by fredericopissarra on November 19, 2020, 03:30:14 PM »
Add 'default rel' at the beginning of your code. This will use RIP relative adddressing (the default for C/C++ compilers for x86-64 mode) and the opcode will be what you expect. Or:

Code: [Select]
call qword [rel __imp_SomeExternalFunction]
25
Using NASM / Re: Linux or DOS
« Last post by fredericopissarra on November 19, 2020, 03:25:00 PM »
Untested! I think that's right. Holler if any problem or if you want to make a '.com' file out of it (model tiny).

Small changes made by me:

Code: [Select]
; PROGRAM.ASM
;
; Compile:
;   nasm -f obj program.asm
;
; link program.obj (using Borland C++ 3.1 or Turbo C 2.1 linker)
;   tlink /n program.obj,program.exe
;
; OBS: DOS don't use '.section' names. The sectios are:
;   'stack', 'code' and 'data' (and 'bss' if it exists).
;
; OBS: I don't think Visual Studio's LINK can handle DOS
;      executables anymore.
;
; OBS: If you want to make sure to use only 8086 instructions,
;      you can use 'cpu 8086', otherwise 386 instructions will be
;      available to you in real mode.

  bits 16
  ;cpu 8086    ; uncomment to make sure 8086 instructions only.

; -------- STACK for the EXE process.
  section stack stack ; first "stack" is name,second is attribute

  resb 256      ; 256 bytes stack (is enough for this small program).
stack_top equ $

; -------- OUR DATA segment
  section data data

Asterisks1 db `*****\r\n$`
Asterisks2 db `*   *\r\n$`

; -------- OUR CODE segment
  section code code

..start:

  ; Need to setup stack!
  mov   ax,stack
  mov   ss,ax
  mov   ax,stack_top
  mov   sp,ax

  mov   ax,data
  mov   ds,ax

  ; print top row.
  lea   dx,[Asterisks1]
  mov   ah,9
  int   0x21

  ; print 3 middle rows.
  mov   cx,3
.loop:
  lea   dx,[Asterisks2]
  mov   ah,9
  int   0x21
  dec   cx
  jnz   .loop

  ; print bottom row.
  lea   dx,[Asterisks1]
  mov   ah,9
  int   0x21

  ; exit(0)
  mov ax,0x4c00
  int 0x21

Tested with NASM and TLINK (Borland C++ 3.1 or Turbo C 2.1) in DOSBOX.
NASM compilation on Linux... Linkage on DOSBOX.
26
Using NASM / Re: Linux or DOS
« Last post by debs3759 on November 18, 2020, 10:04:29 PM »
Untested! I think that's right. Holler if any problem or if you want to make a '.com' file out of it (model tiny).

Looks right to me (assuming the int 21h calls are right)
27
Using NASM / Re: Linux or DOS
« Last post by Frank Kotler on November 18, 2020, 09:44:50 PM »
Oh shift! I used to do this stuff all the time... a long time ago,

This shouldn't need to be "small"... but to try to make it the same...

Code: [Select]
; nasm -f obj program.asm
; link program.obj ; ?

; nasm doesn't use "model"
;.model small

section stack stack ; first "stack" is name, second is attribute
resb 100h

section .data
  Asterisks DB '*****',0DH,0AH,'$'

section .code ; nasm knows ".text" but not for -f obj

..start  ; for -f obj only!

; Main Proc  ; not for nasm

    mov ax, .data
    mov ds, ax
    mov cx, 5

    _loop1:
    mov ah, 9
    lea dx, [Asterisks]  ; "lea" wants "[contents]"
    int 21H
    dec cx
    jnz _loop1
; or just 'loop loop1' decrements cx and jumps if non-zero

; exit cleanly
    mov ah, 4ch
    int 21h

;  Main ENDP ; not for nasm
;END Main ; not for nasm

This prints out:
*****
*****
*****
*****
*****
Untested! I think that's right. Holler if any problem or if you want to make a '.com' file out of it (model tiny).

Code tags: put the word "code" in square brackets, "/code" it the end. Makes it easier to read? and easier to cut and paste!

Best,
Frank

28
Using NASM / Re: Linux or DOS
« Last post by Azrael998 on November 18, 2020, 06:53:08 AM »
Hi Frank,

I installed DOS and assembled the code using MASM but my professor says that it should be assembled using NASM do you know how to convert the code to NASM?.

Here's the MASM code:
.model small
.stack 100h

.data
  Asterisks DB '*****',0DH,0AH,'$'

.code
  Main Proc
    mov ax, @data
    mov ds, ax
    mov cx, 5

    _loop1:
    mov ah, 9
    lea dx, Asterisks
    int 21H
    dec cx
    jnz _loop1

    mov ah, 4ch
    int 21h
  Main ENDP
END Main

This prints out:
*****
*****
*****
*****
*****
29
Using NASM / Suboptimal code generation?
« Last post by EAirPeter on November 18, 2020, 05:18:37 AM »
I found a little bit weird to see nasm generate "FF 14 25 xx xx xx xx" for
Code: [Select]
call qword [__imp_SomeExternalFunction]
where cl (from MSVC) gives "FF 15 xx xx xx xx", which is one byte shorter than what nasm generates, and also is what I am expecting.

I looked them up in Intel's manual, and found "14 25" is the "[scaled_index]+disp32" version with scaled_index = 0, while "15" stands for just "+disp32". I believe they are semantically the same. By my intuition, I think the shorter form should be better so I am some how curious why nasm generates the longer form.

Now the question is, is there any intention of generating the 1-byte longer instruction? or it is just a defect?

Another question, how can I force nasm to generate the 2-byte version of indirect near call?
I know you can do this by "db ff 15 xx xx xx xx", but what I want is a more general solution, like telling nasm to choose a specific form of an instruction (opcode, addressing mode, etc).

Note: the example given is obtained on Windows 10 x64, with nasm targeting win64.
30
Using NASM / Re: Linux or DOS
« Last post by Frank Kotler on November 18, 2020, 03:37:03 AM »
Hi  Azrael998,

Int 21h is dos only. Linux could use sys_write to write one or more assesterisk on the screen. 5x5 might be a problem. What subfunction of Int 21h does the assignment use? Does this draw one big asterisk or a "box" or "block" of 'em? Your best bet might be to install Dosbox or some such, but maybe we can figure our how to do  it in Linux.
   |             *****
 \   /           *     *
-      -   or  *     *  or ?
  /   \          *     *
    |            *****

... this stuff looks poor... I'm thinkin' Dosbox...

Best,
Frank


Pages: 1 2 [3] 4 5 ... 10