News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

to write a string in 16 bit

Started by bcddd214, November 26, 2011, 11:47:23 PM

Previous topic - Next topic

bcddd214

without using any Irvine libraries?

Gunner

If you are using Windows 7 then you can't use interrupts without using a DOS emulator

Interrupt list: http://www.ctyme.com/rbrown.htm

DOS Emulator I use: http://dfendreloaded.sourceforge.net/
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

jj2007

You need link16.exe to build this.

.Model small
.Stack 512
.686 ; you can indeed use 32-bit regs

chr$ MACRO any_text:VARARG
LOCAL txtname
.data
txtname db any_text,"$"
.code
EXITM <OFFSET txtname>
ENDM

.Code

_main proc FAR

; set the DS register to DGROUP (will fail with some Masm versions - use ml 6.15 or higher, or JWasm)
mov ax, @DATA
mov ds, ax

; display the message
mov dx, chr$("Nobody here uses Irvine libraries")
mov ah, 9
int 21h

; wait for a key
mov ah, 0
int 16h

; the DOS equivalent to ExitProcess
mov ax, 4C00h
int 21h

_main endp
end _main


MichaelW


.model small, c
.386
.stack
.data
    str1 db "Hi, I'm Larry, this is my brother Darryl,",13,10
         db "and this is my other brother Darryl.",13,10,0
.code

; -----------------------------------------------
; DOS handles for standard input/output devices.
; -----------------------------------------------

    HSTDIN   EQU 0
    HSTDOUT  EQU 1

; -------------------------------------------------------------
; This proc returns the length of the specified
; null-terminated string in AX.
; -------------------------------------------------------------

szlen proc c uses bx npsz:WORD
    mov bx, npsz
  runLoop:
    cmp BYTE PTR [bx], 0      ; Compare bytes until find null
    jz  @F
    inc bx
    jmp runLoop
  @@:
    mov ax, bx                ; Calc length and return in AX
    sub ax, npsz
    ret
szlen endp

; -------------------------------------------------------------
; This proc calls the Write File or Device function to
; output the specified null-terminated string to STDOUT.
; -------------------------------------------------------------

stdout proc c uses ax bx cx dx npsz:WORD
    invoke szlen, npsz
    mov cx, ax
    mov bx, HSTDOUT
    mov dx, npsz
    mov ah, 40h
    int 21h
    ret
stdout endp

.startup

    invoke stdout, ADDR str1
   
    mov ah, 0
    int 16h

.exit
end

eschew obfuscation

jj2007

#4
Short & crispy:
ml 6.14 with /c
link16.exe with /omf

include \masm32\MasmBasic\Mb16.inc    ; inspired by DednDave
  Init
  mov dx, Chr$("DOS is fun", 13, 10, "isn't it?")   ; display the message
  mov ah, 9      ; the traditional
  int 21h         ; way
  mov cx, Chr$(13, 10, "More fun")   ; display the message
 
Print cx, 13, 10   ; using the cx register
  Print "Real fun", 13, 10   ; the simplest option

  Print Str$(123), " is 123", 13, 10

  Inkey "bye"      ; wait for a key
  Exit
end start

Rockphorr

Quote from: Gunner on November 26, 2011, 11:53:11 PM
If you are using Windows 7 then you can't use interrupts without using a DOS emulator

Interrupt list: http://www.ctyme.com/rbrown.htm

DOS Emulator I use: http://dfendreloaded.sourceforge.net/

thanx you for link.
Strike while the iron is hot - Бей утюгом, пока он горячий


jj2007

New 16-bit macro added above in Mb16a.zip:

Print Str$(123), " is 123", 13, 10
Print Str$(ah), " is ah", 13, 10
Print Str$(cl), " is cl", 13, 10

bcddd214

Quote from: jj2007 on November 26, 2011, 11:56:04 PM
You need link16.exe to build this.

.Model small
.Stack 512
.686 ; you can indeed use 32-bit regs



linker16? I am compiling in 16 bit now a see that this code will switch me to 32 bit?

jj2007

Quote from: bcddd214 on December 23, 2011, 06:42:26 PM
linker16? I am compiling in 16 bit now a see that this code will switch me to 32 bit?

Yes and no. Watch the 66...

16-bit
15AA:000B B07B          MOV     AL,7B
15AA:000D B87B00        MOV     AX,007B
15AA:0010 66            DB      66
15AA:0011 B87B00        MOV     AX,007B

32-bit
00401015        ³?  B0 7B               mov al, 7B
00401017        ³?  66:B8 7B00          mov ax, 7B
0040101B        ³.  B8 7B000000         mov eax, 7B


bcddd214

Quote from: MichaelW on November 27, 2011, 09:04:14 AM



[/quote]

my program lost all functionality when trying to implement the 16 bit version

http://pastebin.com/SuZ8XzD1

bcddd214

Quote from: jj2007 on December 23, 2011, 07:02:06 PM
Quote from: bcddd214 on December 23, 2011, 06:42:26 PM
linker16? I am compiling in 16 bit now a see that this code will switch me to 32 bit?

Yes and no. Watch the 66...

16-bit
15AA:000B B07B          MOV     AL,7B
15AA:000D B87B00        MOV     AX,007B
15AA:0010 66            DB      66
15AA:0011 B87B00        MOV     AX,007B

32-bit
00401015        ³?  B0 7B               mov al, 7B
00401017        ³?  66:B8 7B00          mov ax, 7B
0040101B        ³.  B8 7B000000         mov eax, 7B



I see you are using eax which puts me into 32 bit. I a really trying to stay 16 bit if possible.

bcddd214

i think i almost got it this time but the program hangs??

http://pastebin.com/vm3n1LuP