Hi im working on a bit of homework and rather stuck
this is what im trying to do
and well this is what i have
main.asm
stdio.asm
im stuck on part 1 / 2 atm (for some reason my program atm allows you to input up to 3 character and they will be echo'd onto the screen no idea why only 3 )
anyway what im trying to work on is a if statement i want somthing like
if(AH>=30h | AH <=39)
;the value of the character is 0-9
else(AH>=41h | AH <=51)
;the value is A-Z
how can i do this in nasm assembler?
i have been messing around with :
i want like 2 conditions =>0 <=9
then once i have made sure the value is 0-9 or A-Z then i can do step 3 which i dont really have any idea on how im going to do that either
thanks in advance
this is what im trying to do
Rich (BB code):
0) initialise a temporary numerical value to 00H, base value to 10H and count value to 00H
1) Read in a character
2) Apply series of checks against ‘0’-‘9’ and ‘A’-‘F’ and convert the digit to a numerical value as described above
3) multiply our temporary numerical value by the base (10H) – remember that mul multiplies the src with what is in AL or AX so we need to make sure that the temporary numerical value is moved into AX before we multiply and since AL contains our digit numerical value we will need to push AX to save it for use later - use version b) of mul i.e. src is 16 bit, result in high word in DX (we will discard this) and low word in AX (which we will use). We can safely multiply by the base the first time round as the temporary numerical value will start out as initilised to 0.
5) pop AX so we can get the new numerical digit value and add it to the temporary numerical value
6) increment count of digits converted and go back to 1)
Note – you will also need to echo the digit characters input, but you should ignore i.e. not echo, the non-hex digit termination character.
main.asm
Rich (BB code):
BITS 16 ;Set code generation to 16 bit mode
ORG 0x0100;
SECTION .text;
MAIN:
;call upon the subroutines
call Getch
call Putln
call Putch
call Putln
call Exit
%include "Stdio.asm"
Rich (BB code):
;*************************************************************
;Subroutine Name: Putch
;Function: Outputs a character at the cursor position
; in the console window by calling DOS INT21H
;Entry Conditions: Character to be output in DL
;Exit Conditions: None
;Exceptions: None
;*************************************************************
Putch:
MOV AH, 02h ; display subprogram
INT 21H
RET ; return
;*************************************************************
;Subroutine Name: Getch
;Function: Obtains character input from the keyboard
;Entry Conditions: Character to be moved into DL
;Exit Conditions: None
;Exceptions: None
;*************************************************************
Getch:
MOV ah, 1h ; keyboard input subprogram
int 21h ; read character into al
mov DL, AL
RET ; return
;*************************************************************
;Subroutine Name: Putln
;Function: Outputs a new line at the cursor position
; in the console window by calling DOS INT21H
;Entry Conditions: Character to be output in AH
;Exit Conditions: None
;Exceptions: None
;*************************************************************
Putln: ;new line
mov dl, 0DH ;Carriage return
int 21h
mov dl, 0AH ;Line feed
int 21H
RET ; return
;*************************************************************
;Subroutine Name: Exit
;Function: When called upon it will exit the program
;Entry Conditions: None
;Exit Conditions: None
;Exceptions: None
;*************************************************************
Exit:
mov AX, 04C00H
int 21H
anyway what im trying to work on is a if statement i want somthing like
if(AH>=30h | AH <=39)
;the value of the character is 0-9
else(AH>=41h | AH <=51)
;the value is A-Z
how can i do this in nasm assembler?
i have been messing around with :
Rich (BB code):
CMP DL ,30h ;if (DL>=0)
JGE IF09 ;jump to if09 , if true
then once i have made sure the value is 0-9 or A-Z then i can do step 3 which i dont really have any idea on how im going to do that either
thanks in advance