Hi forum, I am just wondering how I could just use the last two digits of a four digit year the user inputs. For example, I want to drop the [19] from [1960] and just use the [60] which should be 3C in Hex so the registers would read it.

Here is my Data Segment.

NUMPAR		LABEL	    BYTE
MAXLEN		DB	    5		;maximum input length
ACTLEN		DB	    ?
NUMFLD		DB	    8 DUP(' ')
BINFLD		DW	    0
MULT10		DW	    1

And here is my code to accept ASCII characters from the user and convert them to digits. The user should input a four-digit year.

;To accept number.
		MOV	    CX,0
		MOV	    CL,MAXLEN
		LEA	    SI,NUMFLD
CLRIN:
		MOV	    BYTE PTR[SI],020H
		INC	    SI
		LOOP	    CLRIN
;
		MOV	    MULT10,1
		MOV	    BINFLD,0
		MOV	    AH,0AH
		LEA	    DX,NUMPAR
		INT	    21H
		MOV	    CX,10
		LEA	    SI,NUMFLD-1
		MOV	    BL,ACTLEN
		MOV	    BH,0
INPUTNXT:
		MOV	    AL,[SI+BX]
		AND	    AX,000FH
		MUL	    MULT10
		ADD	    BINFLD,AX
		MOV	    AX,MULT10
		MUL	    CX
		MOV	    MULT10,AX
		DEC	    BX
		JNZ	    INPUTNXT
;End input.

Recommended Answers

All 3 Replies

To paraphrase, you want your INPUTNXT loop to only consider the last two characters entered, right?

You already have the information you need to find where those two characters start within NUMFLD : The user entered ACTLEN out of MAXLEN possible characters, so there are ( MAXLEN - ACTLEN ) extra characters at the start that you don't care about. Rather than start converting characters at NUMFLD , use that value as your starting offset.

That really depends on if you want the hex value or a string representation:
This one gets the text value that can be converted to a byte (if necessary);
Pardon the weird labels.

; Compiled with A86 (http://eji.com/a86/)
; This program shows how to get user input with echo.

ORG 100H
	mov ah, 09h
	mov dx, askName;
	int 21h                      ; Ask for year
	
	mov cx, 0ah
	mov si, userInput;            ; Place to store the user name
getName:
	mov ah, 01h
	int 21h                      ; Get input with echo
	
	cmp al, 0dh                  ; 
	je printQuit                 ; Quit if Carriage-return
	
	mov [si], al                 ; Put entered char in user name
	
	cmp byte ptr [finalStop], 24h; is 4th dollar-sign gone?
	jne printQuit                ; if so, buffer is full?, quit
	
	inc si			     ; move the position
	loop getName;		     ; Keep going (looping)
printQuit:
	mov ah, 09h
	mov dx, youEntered;
	int 21h			     ; Print the finished input
	mov dx, lastDigsLabel;
	int 21h
	mov dx, userInput+2;
	int 21h
	
quit:
	int 20h                      ; *** DROP TO DOS ***
	
askName:	db 'Enter a 4-digit year and press enter: $'
youEntered:	db 'You entered', 0dh, 0ah
userInput:	db '$$$'
finalStop:	db '$$'
lastDigsLabel:	db 0dh, 0ah, 'Last two digits are: $'

I figured it out, but thanks though. All I needed to do was divide the date by 100 and take the remainder... So simple... >.<

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.