flat assembler
Message board for the users of flat assembler.
Index
> Main > Show binary representation of a byte variable |
Author |
|
DJ Mauretto 20 Nov 2011, 18:16
Hello,
Try This: Code: macro BinaryPrint1 number { pusha mov bl,80h mov al, number mov si, 8 forLoop: test al, bl jnz NotZeroed PrintChar '0' jmp @f NotZeroed: PrintChar '1' @@: shr bl, 1 dec si test si,si jnz forLoop popa } macro PrintChar ch { pusha mov dl, ch mov ah, 2h int 21h popa } org 100h BinaryPrint1 35 int 20h; _________________ Nil Volentibus Arduum |
|||
20 Nov 2011, 18:16 |
|
bitshifter 20 Nov 2011, 18:41
Making macro for fun is ok, but in real world this would assemble and run slow.
Besides being huge from inline expansion problem. I suggest to use procedure, then reuse only cost sizeof param and call. Here is my super simple 17 byte routine Code: use16 org 0x0100 number_of_the_beast = 666 mov bx,number_of_the_beast call display_bin16 xor ah,ah int 0x16 ret display_bin16: ; bx = value mov ah,0x02 mov cx,16 ;number of bits in value .das_loop: xor dx,dx shl bx,1 adc dl,'0' int 0x21 loop .das_loop ret |
|||
20 Nov 2011, 18:41 |
|
Picnic 21 Nov 2011, 09:45
I can save one more byte
Code: adc dl,'0' ; 3 bytes adc al,'0' ; 2 bytes Code: display_bin16: mov cx, 16 mov ah, 0Eh .das_loop: xor al, al shl bx, 1 adc al, '0' int 10h loop .das_loop ret |
|||
21 Nov 2011, 09:45 |
|
majidkamali1370 21 Nov 2011, 12:05
Can I create one proc for handling 1,2 and 4 byte data?
|
|||
21 Nov 2011, 12:05 |
|
bitshifter 21 Nov 2011, 19:01
Sorry Picnic, but some older BIOS'es use BX register for parameters.
http://www.ctyme.com/intr/rb-0106.htm |
|||
21 Nov 2011, 19:01 |
|
majidkamali1370 21 Nov 2011, 19:07
I don't understand this line of your code
adc al, '0' actually I don't understand where, CF become one. |
|||
21 Nov 2011, 19:07 |
|
AsmGuru62 21 Nov 2011, 19:42
SHL BX,1
It will push bit #15 out into CF. |
|||
21 Nov 2011, 19:42 |
|
Picnic 22 Nov 2011, 10:38
bitshifter wrote: Sorry Picnic, but some older BIOS'es use BX register for parameters. Small but important detail. I missed that |
|||
22 Nov 2011, 10:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.