Author Topic: Linux or DOS  (Read 10533 times)

Offline Azrael998

  • Jr. Member
  • *
  • Posts: 12
Linux or DOS
« on: November 18, 2020, 01:55:09 AM »
Hello everyone, I have an assignment I need to create a program that displays a 5 by 5 asterisk on the screen using int 21H. My question is do I have to use DOS or can I use Linux?, does Linux have system call similar to DOS' int 21H?.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Linux or DOS
« Reply #1 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



Offline Azrael998

  • Jr. Member
  • *
  • Posts: 12
Re: Linux or DOS
« Reply #2 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:
*****
*****
*****
*****
*****
« Last Edit: November 18, 2020, 08:01:47 AM by Azrael998 »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Linux or DOS
« Reply #3 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


Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 221
  • Country: gb
    • GPUZoo
Re: Linux or DOS
« Reply #4 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)
My graphics card database: www.gpuzoo.com

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: Linux or DOS
« Reply #5 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.
« Last Edit: November 19, 2020, 09:22:50 PM by fredericopissarra »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Linux or DOS
« Reply #6 on: November 19, 2020, 07:44:03 PM »
Thanks Debs

Thanks Frederico

Many eyes make fewer bugs!

Best,
Frank