flat assembler
Message board for the users of flat assembler.

Index > DOS > Show Registers (16-bit)

Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 24 May 2007, 20:29
A simple script i wrote in fasm to display CPU registers in Debug style.

Code:
ORG 100H
CALL SHOWR
INT 20H

SHOWR:
PUSH AX BX CX DX SI DI ES BP
PUSH SP SS ES DS CS BP SI DI DX CX BX AX
MOV SI,REGSTR
MOV CX,12
@@:
MOV DL,BYTE [SI]
CALL PUTC
MOV DL,BYTE [SI+1]
CALL PUTC
MOV DL,BYTE [SI+2]
CALL PUTC
ADD SI,3
POP AX
CALL HEXWORD
MOV DL, ' '
CALL PUTC
LOOP @B
POP BP ES DI SI DX CX BX AX
CALL NEWLINE
RET

HEXWORD:
PUSH AX
MOV AL,AH
CALL HEXBYTE
POP AX
CALL HEXBYTE
RET

HEXBYTE:
PUSH AX
ROL AL,4
CALL DIGIT
POP AX
CALL DIGIT
RET

DIGIT:
PUSH AX DX
AND AL,0FH
ADD AL,30H
CMP AL,'9' + 1
JC @F
ADD AL,7
@@:
MOV DL,AL
CALL PUTC
POP DX AX
RET
        
PUTC:
PUSH AX
MOV AH,02H
INT 21H
POP AX
RET

NEWLINE:
PUSH AX DX
MOV AH,02H
MOV DL,0AH
INT 21H
MOV DL,0DH
INT 21H
POP DX AX
RET

REGSTR DB 'AX=BX=CX=DX=DI=SI=BP=CS=DS=ES=SS=SP='
    


Image


Last edited by Picnic on 21 Mar 2020, 10:24; edited 2 times in total
Post 24 May 2007, 20:29
View user's profile Send private message Visit poster's website Reply with quote
jatos



Joined: 04 Nov 2006
Posts: 20
jatos 31 May 2007, 21:50
Thanks for that. This program is something I really wanted!

_________________
Jamie
Post 31 May 2007, 21:50
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 11 Jun 2007, 19:50
Be well jatos!

Here is another script i wrote in fasm. It displays memory contents.
It's my first attempt to use a macro.

Code:
MACRO PUTC [ARG] {
 LOCAL EXIT
 IF ARG EQTYPE '' | ARG EQTYPE 0
  MOV DL,ARG
 ELSE
  CMP DL,20H
  JAE EXIT
  MOV DL,'.'
  END IF
  EXIT:
  MOV AH,2
  INT 21H
 }
 
MACRO INIT REGAX,REGSI,REGDI {
 MOV AX,REGAX
 MOV SI,REGSI
 MOV DI,REGDI
 MOV ES,AX
 MOV BX,TABLE
 }
 

ORG 100H
INIT 1234H,100H,200H   ;SEGMENT ADDRESS,STARTING ADDRESS,ENDING ADDRESS
CALL DUMP
RET

DUMP:
PUTC 13,10
MOV DX,ES
CALL HEXWORD
PUTC ':'
MOV DX,SI
CALL HEXWORD
PUTC ' '
MOV CX,16
PUSH SI
@@:
MOV DL,[ES:SI]
INC SI
CALL HEXBYTE
PUTC ' '
LOOP @B
POP SI
MOV CX,16
PUTC ' '
@@:
MOV DL,[ES:SI]
INC SI
PUTC DL
LOOP @B
CMP SI,DI
JL DUMP
RET
        
HEXWORD:
XCHG DH,DL
CALL HEXBYTE
XCHG DH,DL
CALL HEXBYTE
RET

HEXBYTE:
MOV AL,DL
SHR AL,4
XLATB        
MOV AH,0EH 
INT 10H
MOV AL,DL
AND AL,0FH 
XLATB            
MOV AH,0EH
INT 10H
RET

TABLE DB '0123456789ABCDEF'
    
Post 11 Jun 2007, 19:50
View user's profile Send private message Visit poster's website Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m 30 Jun 2007, 10:57
Cooool eh!
Post 30 Jun 2007, 10:57
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 01 Jul 2007, 21:54
Code:
; use FASMD and press F9 to assemble / run, then Alt+F5 to see screen
;
; EDIT: fixed to be 8086 compatible
;
; 30 bytes (could it be smaller??)

org 100h

mov ax,0BEEFh
call hexword
ret

hexword:
          mov cx,4
.begin:
          push cx
          mov cl,4
          rol ax,cl
          pop cx
          push ax
          and al,0Fh
          cmp al,10
          sbb al,69h
          das
          int 29h
          pop ax
          loop .begin
.ret:
          ret
    
Post 01 Jul 2007, 21:54
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 10 Jan 2008, 20:08
Again the 16-bit registers for anyone interested.
Code:
; Display 16-bit registers

showr:
  pusha
       pushf
       push sp ss es ds cs bp si di dx cx bx ax
    mov si,regstr
       mov cl,12
.reg:
      lodsb
       int 29h
     lodsb
       int 29h
     lodsb
       int 29h
     mov ch,4
    pop ax                                 ; ax bx cx dx ..
.digit:
         rol ax,4
         push ax
         and al,0fh
         cmp al,10
         sbb al,69h
         das
         int 29h    
         pop ax
         dec ch
         jnz .digit
         mov al,' '
   int 29h        
     loop .reg
   mov al,13
   int 29h
     mov al,10
   int 29h
     popf
        popa
        ret
         
    
         regstr db 'AX=BX=CX=DX=DI=SI=BP=CS=DS=ES=SS=SP='
    

_________________
Hobby BASIC Interpreter
Post 10 Jan 2008, 20:08
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 12 Jan 2008, 01:36
good, thimis, good good good! Very Happy
and for somebody interrested for non dos dependance:


Description: need some modifications if you need.

easily bootable

Download
Filename: whatsegment.zip
Filesize: 972 Bytes
Downloaded: 746 Time(s)

Post 12 Jan 2008, 01:36
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 13 Jan 2008, 13:08
Thank you edfed.
P.S I used code from rugxulo's post above as it appears.
Post 13 Jan 2008, 13:08
View user's profile Send private message Visit poster's website Reply with quote
Slai



Joined: 11 Jan 2006
Posts: 40
Location: NY/Bulgaria
Slai 22 Jan 2008, 20:21
rugxulo I do not get why do you use
push cx
mov cl,4
rol ax,cl
pop cx
instead of just "rol ax, 4", but you can save few bites this way.
Post 22 Jan 2008, 20:21
View user's profile Send private message Reply with quote
Slai



Joined: 11 Jan 2006
Posts: 40
Location: NY/Bulgaria
Slai 22 Jan 2008, 20:28
rugxulo your code helped me to improve my ShowHex macro with the push/pop ax, thanks! And I learned from you about the int 29h, does that work on all PCs ?
Post 22 Jan 2008, 20:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Jan 2008, 20:51
Quote:

instead of just "rol ax, 4", but you can save few bites this way.

Because "rol reg, imm8" is not available in 8086 (except for "rol reg, 1").
Post 22 Jan 2008, 20:51
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 23 Jan 2008, 01:31
> Because "rol reg, imm8" is not available in 8086 (except for "rol reg, 1").

Code:
push cx
mov cl,4
rol ax,cl
pop cx 
    


Great ^^^ code, if you need obfuscation or save 2 bytes Laughing

Code:
  rol ax,1 ; This eats 2 BYTES !!!
  rol ax,1
  rol ax,1
  rol ax,1
    


Would be the "bloated" 8086-compatible solution Idea

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 23 Jan 2008, 01:31
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 23 Jan 2008, 23:38
Code:
 
push cx si 
mov si,roller
mov cl,[si] 
rol ax,cl 
pop si cx  
    

can be modular too. use more bytes, but for memory programable rol, it's good.
Post 23 Jan 2008, 23:38
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Jan 2008, 23:47
And what was the problem with
Code:
push cx  
mov cl, [roller]  
rol ax, cl  
pop cx    
?
Post 23 Jan 2008, 23:47
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 25 Jan 2008, 03:48
First of all, sorry, thimis, about silently updating the code without PM'ing you or something. Yeah, when I initially posted the code using rol ax,4, I forgot about 8086-compatible code, which doesn't really waste much of anything and runs everywhere. So I personally prefer compatibility in such a case.
Post 25 Jan 2008, 03:48
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 25 Jan 2008, 04:26
the problem was that si can be defined before, and the last 3 instructions used in a loop.

Code:

         push si
         mov si,[roller]
;assume esi never changed for all but the index of roller
...
         push cx
         mov cl,[si]
         rol ax,cl
         pop cx
...
         inc si
         push cx
         mov cl,[si]
         rol ax,cl
         pop cx
         pop si
...
roller db 5,4,3,2,1,4,3,4,3,4,0
    
Post 25 Jan 2008, 04:26
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 25 Jan 2008, 20:23
rugxulo wrote:
First of all, sorry, thimis, about silently updating the code without PM'ing you or something.


No problem rugxulo, i was aware about this compatibility issue.

_________________
Hobby BASIC Interpreter
Post 25 Jan 2008, 20:23
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 18 May 2009, 22:04
Post 18 May 2009, 22:04
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 02 Nov 2012, 09:36
rugxulo wrote:
Code:
; use FASMD and press F9 to assemble / run, then Alt+F5 to see screen
;
; EDIT: fixed to be 8086 compatible
;
; 30 bytes (could it be smaller??)

org 100h

mov ax,0BEEFh
call hexword
ret

hexword:
          mov cx,4
.begin:
          push cx
          mov cl,4
          rol ax,cl
          pop cx
          push ax
          and al,0Fh
          cmp al,10
          sbb al,69h
          das
          int 29h
          pop ax
          loop .begin
.ret:
          ret
    

Sorry to revive an old (but interesting) thread.
Anyway, yes it can be smaller, by 2 bytes (28 vs 30)...
Code:

org 0x0100
use16

main:
 mov dx,0xBEEF
 call hexword
;mov ah,0x08
;int 0x21
 ret

hexword:
 mov cx,0x0404
.again:
 rol dx,cl
 mov al,dl
 and al,0x0F
 cmp al,0x0A
 sbb al,0x69
 das
 int 0x29
 dec ch
 jnz .again
 ret
    
Uncomment the two lines if you need to pause in console...

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 02 Nov 2012, 09:36
View user's profile Send private message Reply with quote
ght2142



Joined: 11 Oct 2012
Posts: 3
ght2142 03 Nov 2012, 09:53
I must say Picnic, I am impressed. Very Happy
Post 03 Nov 2012, 09:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.