flat assembler
Message board for the users of flat assembler.

Index > DOS > Tutorial: Convert byte to binary

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 03 Jan 2013, 21:10
Code:
org 100h
mov bh,123       ; Byte to convert
mov ah,2
mov cx,8
bits:
      shl bx,1
    jc carry
    mov dl,'0'
        jmp print
carry:
     mov dl,'1'
print:
  int 21h
loop bits
int 20h
    
Post 03 Jan 2013, 21:10
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 03 Jan 2013, 21:19
Code:
org 100h
mov bh,123      ; Byte to convert
mov ah,2
mov cx,8
bits:
        shl bx,1
        mov dl,'0'
        adc dl, 0 ; If CF is set then '1' will be printed, otherwise '0' is printed.
        int 21h
loop bits
int 20h    
Post 03 Jan 2013, 21:19
View user's profile Send private message Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 03 Jan 2013, 21:48
Great.
Thanks!
Post 03 Jan 2013, 21: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 03 Jan 2013, 22:02
Code:
org 100h
mov bh,123      ; Byte to convert
mov ah,2
mov cx,8
mov dh,'0'
bits:
        shl bx,1
        mov dl,dh
        adc dl, 0 ; If CF is set then '1' will be printed, otherwise '0' is printed.
        int 21h
loop bits
int 20h
    

? faster ?
Post 03 Jan 2013, 22:02
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1619
Location: Toronto, Canada
AsmGuru62 03 Jan 2013, 22:12
@edfed: JMPs are minimized, so most likely it is faster.
And the code is more elegant.
Post 03 Jan 2013, 22:12
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 03 Jan 2013, 22:20
mov dl,dh faster than mov dl,'0'?

Smile
Post 03 Jan 2013, 22:20
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 03 Jan 2013, 22:21
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:06; edited 1 time in total
Post 03 Jan 2013, 22:21
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 03 Jan 2013, 22:22
jmp there = mov eip,there

i dislike the mov, it is a very bastard instruction.
Post 03 Jan 2013, 22:22
View user's profile Send private message Visit poster's website Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 03 Jan 2013, 22:36
Hi guys (all):

I sincerely admire your assembly-optimizing wisdom.

Why don't you share it via a series of "Best Practices:" posts (just a suggestion) so that a volunteer can accumulate them and perhaps write a booklet about FASM & DOS?

Cheers & Regards,
Ciper
Post 03 Jan 2013, 22:36
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 03 Jan 2013, 23:03
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:06; edited 12 times in total
Post 03 Jan 2013, 23:03
View user's profile Send private message Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 03 Jan 2013, 23:07
Let's stop this nonsense.

MOV is the single most important instruction in the x86 instruction set...

...maybe after NOP Wink

ps: Even a jmp is a mov, after all.
Post 03 Jan 2013, 23:07
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 03 Jan 2013, 23:18
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:06; edited 2 times in total
Post 03 Jan 2013, 23:18
View user's profile Send private message Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 03 Jan 2013, 23:21
Why?
What is the benefit?

More importantly: What is the idea?

How do you MOVe a value into a register?

Just trying to understand...


Last edited by Ciper on 03 Jan 2013, 23:30; edited 1 time in total
Post 03 Jan 2013, 23:21
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 03 Jan 2013, 23:29
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:06; edited 3 times in total
Post 03 Jan 2013, 23:29
View user's profile Send private message Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 03 Jan 2013, 23:35
This was a soi-disant tutorial for God's sake!

Are we supposed to obfuscate tutorials?
Post 03 Jan 2013, 23:35
View user's profile Send private message Visit poster's website Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 03 Jan 2013, 23:55
@HaHaAnonymous: Our goal in practicing assembly is not to hack but to learn. We want to practice x86 & DOS because it is much easier than x64.

Please do not make assembly unapproachable to newcomers; FASM has the unique goal of making the x86 assembler easy (first for its author then for everybody else). If your goal is hacking, I am sure there are other venues.
Post 03 Jan 2013, 23:55
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 04 Jan 2013, 00:06
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:06; edited 1 time in total
Post 04 Jan 2013, 00:06
View user's profile Send private message Reply with quote
Ciper



Joined: 01 Jan 2013
Posts: 27
Ciper 04 Jan 2013, 00:48
We are all people who dislike Intel CPUs; but we try to cope with them Sad
Post 04 Jan 2013, 00:48
View user's profile Send private message Visit poster's website Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 204
ACP 05 Jan 2013, 21:36
Ciper wrote:
Hi guys (all):

Why don't you share it via a series of "Best Practices:" posts (just a suggestion) so that a volunteer can accumulate them and perhaps write a booklet about FASM & DOS?


While personally I think that every book idea is a good idea the problem with this particular one is that you already have it all in few great books from DOS and 16bit Windows era. The only difference is that they target MASM, TASM or A86 and not FASM but since FASM roots are in TASM Ideal mode (which actually always made me sad that even in TASM 5 Users Guide you had sample programs written only in MASM mode) if you find a good book about TASM & DOS you are setup for FASM too in most cases.
Post 05 Jan 2013, 21:36
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 05 Jan 2013, 21:46
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:05; edited 1 time in total
Post 05 Jan 2013, 21:46
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.