News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Beginner...Masm64 new install Richard-001.asm

Started by Richard, December 27, 2020, 12:29:45 PM

Previous topic - Next topic

Mikl__

Hi, Richard! Happy New Year!
Why are you writing 16-bit programs for DOS (the DOS died in 1995) if you want to learn how to program for 64-bit Windows? Why not start with 64-bit programming right away? I knew there are many perverts in the European Union, but I had no idea the scale and did not know that this would affect the programming in assembly language...

Richard

@Miki__

I am actually trying to avoid 16-bit programs (via DOSbox + MASM 5.1 (16 bit)) - an important aim of mine is to convert all (or most) of my existing 16-bit assembly stuff to a "newer" assembly platform than my current 16-bit combo. I have only just started with MASM 64 (32) SDK and it looks like it will be quite some time until I am up and going.

I am also using QB64 (BASIC x64) for higher level programming but trying to interface into assembly for ultimate speed performance for straight forward simple sounding tasks (e.g. sorting fixed length strings and graphics) - however my ability (at this stage) prevents me using x32 and x64 assembly.

Also I am trying out FreeBASIC (DOS version) in a similar manner - with the ultimate aim of a DOS like environment WITHOUT windows present. Windows 10 x64  has proven to me to be unstable and sometimes certain results are unpredictable (as if it was throwing in random events). I have given up with windows for a high precision timer (approaching microseconds on my 2.4 GHz Intel i7 x64 computer) - it displays using an API resolution down to microseconds but repeatability/accuracy is extremely poor for me.

_japheth

Quote from: Richard on December 31, 2020, 04:32:56 PM
Also I am trying out FreeBASIC (DOS version) in a similar manner - with the ultimate aim of a DOS like environment WITHOUT windows present.

Well, here,'s your sample program, translated to 64-bit DOS: :bgrin:

;  Richard-001.asm
;
;  This program puts YELLOW flashing X in TOP ROW CORNERS and WHITE X in BOTTOM ROW CORNERS
;  works with DOSbox + MASM 5.1(16 bit)

name     Xy                   ; Richard-001.asm

.x64
.model flat
; .stack  100
option casemap:none

include dpmi.inc

@int macro no
call int_&no
endm

.data

MSG DB 'X$'                   ; Message to print is "X"   $ terminated string    MSG DB "X$",0

dosmem dw 0     ;segment address DOS memory
rmcs RMCS <> ;DPMI real-mode call structure

.code

start:

;push  ds

;--- allocate 16*16 bytes dos memory
mov ah,48h
mov bx,10h
@int 21h
mov ax,rmcs._BX
mov dosmem,ax
                              ; put YELLOW flashing X at TLHC (Top Left Hand Corner)
mov ah,02h
mov bh,00h                    ; page number 0
mov dh,00h                    ; 00h is top row
mov dl,00h                    ; 00h is left column
@int 10h                       ; VIDEO - set cursor position (FirstRow, FirstColumn)     
mov ah,09h
mov al,58h                    ; "X" char to display
mov bh,0                      ; page number
mov bl,8eh                    ; attribute e= 14. = YELLOW   8x = flashing
mov cx,01h                    ; number of times to write character
@int 10h                       ; VIDEO - write character and attribute at cursor position       

if 0                          ; put YELLOW flashing X at TRHC (Top Right Hand Corner)
push  ds
mov ax, 0b800h                ; need preceeding 0 else is name ;mov ax,0xb800
push ax
pop ds
mov word ptr ds:[0+158],8e58h ; YELLOW flashing X TRHC (FirstRow, LastColumn)   ;[0],0x0e58       
pop ds                        ; LastColumn(=79.)*2 since WORD (CharByte+AttributeByte)
else
mov word ptr flat:[0b8000h+158],8e58h
endif

                              ; put X (only WHITE) at BLHC (Bottom Left Hand Cormer)
mov ah,02h
mov bh,00h                    ; page number 0
mov dh,18h                    ; 00h is top row
mov dl,00h                    ; 00h is left column
@int 10h                       ; VIDEO - set cursor position  (LastRow, FirstColumn)     
mov ah,2
mov dl,58h                    ; X @ cursor
INT 21h                       ; DOS 1+ - write character to standard output


                              ; put X (only WHITE) AT ~BRHC (approx Bottom Right Hand Corner)
mov ah,02h
mov bh,00h                    ; page number 0
mov dh,18h                    ; 00h is top row
mov dl,79-1                   ; 00h is left column - cannot write to LastColumn (=79.) since CrLf
@int 10h                       ; VIDEO - set cursor position (LastRow, LastColumn-1)

;push ds       
;mov ax,@DATA                  ; resolved by linker
;mov ds, ax
lea rdx, MSG

mov cx,sizeof MSG ;copy MSG to conventional memory
call copy2dos

mov ah,09h                    ; DOS 1+ write string to standard output
@int 21h                       ; DS:DX -> $ terminated string  return al = 24h the "$" terminating the string
;pop ds


                              ;  SET CURSOR POSITION ~HALF-WAY UP SCREEN
mov ah,02h
mov bh,00h                    ; page number 0
mov dh,08h                    ; 00h is top row
mov dl,40h                    ; 00h is left column
@int 10h                       ; VIDEO - set cursor position mid screen       

;pop ds
MOV Ax,4C00H                  ; - terminate with return code
INT 21h                       ; EXIT     

retf

int_10h proc
mov rmcs._AX, ax
mov rmcs._DX, dx
mov rmcs._BX, bx
mov rmcs.rSSSP,0
lea rdi,rmcs
xor cx,cx
mov bx,10h
mov ax,0300h
int 31h
ret
int_10h endp

int_21h proc
mov rmcs._AX, ax
mov rmcs._DX, 0
mov rmcs._BX, bx
mov cx,dosmem
mov rmcs.rDS,cx
mov rmcs.rSSSP,0
lea rdi,rmcs
xor cx,cx
mov bx,21h
mov ax,0300h
int 31h
ret
int_21h endp

copy2dos proc   ;copy CX bytes from RDX to dosmem
push rdi
push rsi
movzx edi,dosmem
shl edi,4
movzx ecx,cx
mov rsi,rdx
rep movsb
pop rsi
pop rdi
ret
copy2dos endp

        end start


It works, I tested it. However, I'm afraid it won't run in DOSBox - and most likely also NOT in VBox, because those virtualizers won't emulate a 64-bit cpu ( at least not if you choose DOS as environment ).

It may work in Qemu, though. AND: it works on bare metal.

You might be able to assemble the source with Masm 64-bit (if you delete the .x64 line ) - but MS has decided that mixing 64-bit and 16/32-bit code is something that nobody needs or wants. I used jwasm instead.

Attached is a zip that contains the source, the tools required and a MAKE.BAT to generate the executable.



Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

Richard

@_japheth

Thanks for reply.

I do not see the attached zip file etc - please check.

Also please attach the exe file as well in case I cannot generate for some reason.

Richard

@_japheth

Just tried your zip and ran MAKE.BAT

In Windows 10 x64 File Explorer (double clicking) got the following ERROR MESSAGE...

The C:\...\Richard-001.exe application cannot run in WIN32 mode.

Any idea how to overcome this error?