1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

アセンブラ10/16進表示サンプル

Last updated at Posted at 2024-08-30

x64 16進表示

disp16.s
# Assembly (as, x64, Linux)
.intel_syntax noprefix

.data
msg:	.ascii	"xxxxxxxx\n"
len = . - msg

.text
hex:	.ascii	"0123456789ABCDEF"

.global _start
_start:
	mov	edx, 0x0123cdef
	mov	rdi, offset msg
	mov	ebx, offset hex
	mov	ecx, 8
1:
	mov	al, dl
	and	al, 0x0f
	xlat
	ror	edx, 4
	dec	ecx
	mov	[rdi + rcx], al
	jnz	1b

	mov	edx, len
	mov	rsi, offset msg
	mov	edi, 1		# stdout
	mov	eax, 1		# write
	syscall
	xor	edi, edi
	mov	eax, 60		# exit
	syscall

x64 10進表示

disp10.s
# Assembly (as, x64, Linux)
.intel_syntax noprefix

.data
msg:	.ascii	"xxxxxxxxxx\n"
len = . - msg

.text
.global _start
_start:
	mov	eax, -1
	mov	rdi, offset msg
	mov	ebx, 10
	mov	ecx, 10
1:
	xor	edx, edx
	div	ebx
	add	dl, '0'
	dec	ecx
	mov	[rdi + rcx], dl
	jnz	1b

	mov	edx, len
	mov	rsi, offset msg
	mov	edi, 1		# stdout
	mov	eax, 1		# write
	syscall
	xor	edi, edi
	mov	eax, 60		# exit
	syscall

x86 16進表示

disp16.asm
# as --32 -o disp16.o disp16.s
# ld -m elf_i386 -o disp16 disp16.o

.intel_syntax noprefix

.data
msg:	.ascii	"xxxxxxxx\n"
len = . - msg

.text
.global _start
_start:
	mov	edx, 0x0123cdef
	mov	edi, offset msg
	call	tohex

	mov	edx, len
	mov	ecx, offset msg
	mov	ebx, 1		# stdout
	mov	eax, 4		# write
	int	0x80
	xor	ebx, ebx
	mov	eax, 1		# exit
	int	0x80

tohex:
	mov	ebx, 8
1:
	mov	al, dl
	and	al, 0x0f
	cmp	al, 10
	sbb	al, 0x69
	das
	ror	edx, 4
	dec	ebx
	mov	[edi+ebx], al
	jnz	1b
	ret

V30 16進表示

disp16.asm
; ml /c disp16.asm
; link16 /t disp16.obj;
.186
.model tiny
.code
	org	0100h
start:
	mov	dx, 0f90ah
	mov	di, offset msg
	call	tohex
	mov	dx, offset msg
	mov	ah, 09h
	int	21h
	ret

tohex:
	mov	bx, 4
@@:
	mov	al, dl
	and	al, 0fh
	cmp	al, 10
	sbb	al, 69h
	das
	ror	dx, 4
	dec	bx
	mov	[di+bx], al
	jnz	@b
	ret

msg	db	'xxxx',0dh,0ah,'$'
end start

Z80 16進表示

disp16.asm
;10 bload "program.bin",r

CHPUT	equ	$00a2

	org	$d000
start:
	ld	de, $f90a
	ld	hl, msg + 3
	call	tohex4

	ld	hl, msg
L1:
	ld	a, (hl)
	or	a
	ret	z
	call	CHPUT
	inc	hl
	jr	L1

tohex4:
	call	tohex2
	ld	e, d
tohex2:
	ld	a, e
	call	tohex1
	ld	a, e
	rept 4
	rra
	endm
tohex1:
	and	$0f
	cp	10
	sbc	a, $69
	daa
	ld	(hl), a
	dec	hl
	ret

msg	db	'xxxx',$0d,$0a,0
end start

disp16b.asm
disp16b.asm
;10 bload "program.bin",r

CHPUT	equ	$00a2

	org	$d000
start:
	ld	hl, $f90a
	ld	de, msg
	call	tohex

	ld	hl, msg
L1:
	ld	a, (hl)
	or	a
	ret	z
	call	CHPUT
	inc	hl
	jr	L1

tohex:
	ld	b, 4
tohex1:
	xor	a
	rept 4
	add	hl, hl
	rla
	endm
	cp	10
	sbc	a, $69
	daa
	ld	(de), a
	inc	de
	djnz	tohex1
	ret

msg	db	'xxxx',$0d,$0a,0
end start

Z80 10進表示

disp10.asm
;10 bload "program.bin",r

CHPUT	equ	$00a2

	org	$d000
start:
	ld	hl, -1
	ld	de, msg
	call	todec

	ld	hl, msg
L1:
	ld	a, (hl)
	or	a
	ret	z
	call	CHPUT
	inc	hl
	jr	L1

todec:
	ld	bc, 10000
	call	todec1
	ld	bc, 1000
	call	todec1
	ld	bc, 100
	call	todec1
	ld	bc, 10
	call	todec1
	ld	a, l
	add	a, '0'
	ld	(de), a
	ret
todec1:
	ld	a, '0' - 1
	or	a
todec2:
	sbc	hl, bc
	inc	a
	jr	nc, todec2
	add	hl, bc
	ld	(de), a
	inc	de
	ret

msg	db	'xxxxx',$0d,$0a,0
end start

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?