hexout.asm
; hexout.asm
; MASM32
.model tiny
stdout equ 1
lf equ 0ah
cr equ 0dh
.data
hexlist db '0123456789abcdef'
szsp db 'sp', 0
szcs db 'cs', 0
szds db 'ds', 0
szss db 'ss', 0
buf db '=[', 4 dup(?), ']', cr, lf, 0
.code
org 100h
start:
push sp
mov ax, offset szsp
push ax
call dmpword
add sp, 4
push cs
mov ax, offset szcs
push ax
call dmpword
add sp, 4
push ds
mov ax, offset szds
push ax
call dmpword
add sp, 4
push ss
mov ax, offset szss
push ax
call dmpword
add sp, 4
mov ax, 4c00h
int 21h
; dump word
dmpword proc
push bp
mov bp, sp
mov dx, [bp+4] ; 出力する文字列
call puts
mov dx, [bp+6] ; 出力するword
mov di, offset buf+5 ; 出力バッファ
mov cx, 4
dmpword_loop:
mov si, dx ; half byte
and si, 0fh
mov al, byte ptr [si+offset hexlist]
mov byte ptr [di], al
dec di
push cx
mov cl, 4
shr dx, cl ; 4bit右シフト
pop cx
loop dmpword_loop
mov dx, offset buf
call puts
pop bp
ret
dmpword endp
; put string
; dx: zero-terminated string
puts proc
mov bx, dx
xor cx, cx
puts_loop:
cmp byte ptr [bx], 0
jz puts_out
inc bx
inc cx
jmp puts_loop
puts_out:
mov bx, stdout
mov ah, 40h
int 21h
ret
puts endp
end start
最終更新:2017年10月28日 08:59