Hey again everyone, it's been a while since I've posted here.. What I'm trying to do, is get the command-line argument and convert it to hexidecimal. Example, if the file is named 'test', you would call it with
test 72
Or something similar.
I have it working, but after MUCH examining what the shl\shr instructions do to Binary values, and what it ends up with in Hex, I have found that it converts the value '72' into 7020 (So, this displays the colors correctly.. but only sets it to the first two digits, 70.. so I end up with a white background\black text)
What I was thinking as a solution, was to somehow trap JUST the 4 binary digits.. From what I see, this would be called a Nybble?
Example.. 00110010 binary = 32 hexidecimal, when it gets shifted into AH it turns into
00100000 (20), while it should be a 2. A solution would be to pull out JUST the first 4 bits, '0010' which would be a 2, maybe then I could add those two to the same byte position and it would make one hexidecimal value.
However.. When trying this for my first time...
mov byte [store + 0],ah
lodsb
add byte [store + 0],ah
With 72 as the argument.. it became a 90? Which is a blue background, black text. (I see why, 7 + 2 = 9).. But, Is it possible to do 70 + 2 = 72?
I am on a Windows OS and assembling with NASM16
I know, this program is a little sloppy, but I'm just using it as a 'test' for my other program "Linecol".. Look at it on Youtube if you have the time please, my username is Goalatio.
Here's my code, the library that I am using will be below the code.
Also.. I'd like to thank "NotNull" for all of the help he has supplied me, you have really gotten me into Assembly language.. and much of what I know would not have been possible had you not showed me a few simple commands.
[org 0100h]
%include "Library.asm"
[section .text]
arg ;Get arguments
write ;Display arguments
mov si,bx ;Put arguments into SI
lodsb ;Advance one position
shl ax,12 ;Shift ax left 12 times to get AL into AH
mov byte [store + 0],ah ;Place the attribute into first spot of storage
xor ax,ax ;Zero-out AX
lodsb ;Advance once more
shl ax,12 ;Shift ax left 12 times to get AL into AH
mov byte [store + 1],ah ;Place this in the second part of the storage
color 80,[store],0 ;Use library to display a colored line with new colors
string hello ;Use library to display "Hello"
EXIT:
exit 0 ;Exit with ERRORLEVEL of 0
[section .data]
store times 2 db 0 ;Where color attributes are store
hello db "Hello", 13, 10, "$" ;The test message
And the library it needs...
;===========================================
;string - displays the string passed as an argument
;===========================================
%macro string 1
xor dx,dx
xor ah,ah
mov dx,%1 ;Move the passed string into DX
mov ah,9 ;Function 09h, display string
int 21h ;Call DOS
%endmacro
;===========================================
;===========================================
;exit - exits with passed errorlevel
;===========================================
%macro exit 1
mov AH,4CH ;Terminate process DOS service
mov AL,%1 ;Pass this value back to ERRORLEVEL
int 21H ;Call DOS to exit
%endmacro
;===========================================
;arg - Gets the argument and passes it to DX
;===========================================
%macro arg 0
xor bx, bx ;Zero out BX
mov bl, [cs:0x80] ;Get Command Tail Length
mov byte [bx+0x81],'$' ;Place a $ on command tail
mov bx, 0x82 ;place offset of command tail in BX.
mov dx,bx ;Move offset into DX
%endmacro
;===========================================
;write - writes the string passed into DX
;Caller must pass:
;String or value into DX
;===========================================
%macro write 0
mov ah,9 ;Function 9, display string
int 21h ;Call DOS to display it
%endmacro
;===========================================
;color - sets color while printing characters
;params:
;1: Amount of times to repeat
;2: HEXIDECIMAL color value
;3: Character to print
;===========================================
%macro color 3
mov cx,%1 ;CX value = amount of chars to print
mov bl,%2 ;BL value = HEXI color attr
mov al,%3 ;AL value = character to print
mov ah,9 ;Function 9, display char
int 10h ;Call the SCREEN vector
%endmacro
And.. my "Quick-compilation" batch file.. You are free to keep any of this code for your own use\learning purpose if you like.
@echo off
:Start
cls
set fn=Test
nasm16 %fn%.asm -o %fn%.com
echo.
%fn% 72
echo.
echo Errorlevel return value: %errorlevel%
pause>nul