NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Azrael998 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?.
-
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
-
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:
*****
*****
*****
*****
*****
-
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...
; 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
-
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)
-
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:
; 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.
-
Thanks Debs
Thanks Frederico
Many eyes make fewer bugs!
Best,
Frank