Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help!!! How to write binary to the screen?

Status
Not open for further replies.

siutat

Programmer
Mar 31, 2001
1
AU
I am a beginner in Assembly and just receievd an assignment on this area with one procedure look like this, could someone be able to tell me how to implement it? I have absloutly no idea. Thank you!

AppendBinary PROC
; append the binary representation of the accumulator contents to a string
; with the write starting at address DS:SI
; pre: BX specifies whether AL or AX is to be output (if BX=0 output AL otherwise AX)
; post: the binary representation of the value in the specified accumulator
; has been appended (with MSB leftmost) starting at the address DS:SI
; AND DS:SI points to the char immediately following the appended chars
; AND all registers (excluding SI) are preserved

; ========================================================================
; About 20 instructions in this procedure
; ========================================================================

ret
AppendBinary ENDP
 
Algo:

PUSHALL except SI
x=1; // let "x" be a character

loop:

temp = input;
and (input) , x
if zero flag set,
move ds:[si], 30h // Ascii for "0"
else
move ds:[si],31h // Ascii for "1"
inc si
x = x << 1;
input = temp;
if (x != 0)
Jump to loop

POPall except SI
return; Thatz it :)
Do not rejoice that ur code works.
it might be a special case of an error :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top