;========================================== ;A little assembly app that shows the current date and time. ;It can be done a lot easier, but this way you will ;see how to do some basic memory manipulation, and how to use 'variables'. 逆风编程精品 ;==========================================
.model small .stack
;=========================== ;Data segment starts here ;=========================== .data date_str db "Current date is: yyyy-mm-dd", 0Ah, 0Dh, "$" time_str db "Current time is: hh.mm.ss:xx", 0Ah, 0Dh, "$" min_size dw ? padd_chr db ?
;=========================== ;Code segment starts here ;=========================== .code main proc mov ax, seg @data ;First we get the data segment address mov ds, ax ;and store it into ds
mov [min_size], 02h ;Results should always be at least two digits mov [padd_chr], '0' ;Use '0' as padding-character
mov ah, 2Ah ;Then we call int 21h,2Ah, which will give int 21h ;us the current date
lea di, date_str ;Then we load the address of the date_str string add di, 17 ;and set si to point at the first y in yyyy-...
mov ax, cx ;Next we mov cx to ax and call todec ;call todec inc di ;We skip the '-' character...
xor ax, ax ;Then we empty ax mov al, dh ;And set the low-byte of ax to dh call todec inc di ;Skip character in string...
xor ax, ax ;Empty ax mov al, dl ;Set low-byte to dl call todec ;Convert it to base10
lea di, time_str ;Now we load the time_str string add di, 17 ;And set the correct pointer offset
mov ah, 2Ch ;And then we call int 21h,2Ch int 21h ;which will give us the current time
xor ax, ax ;Empty ax mov al, ch ;Set low-byte to ch call todec ;Convert it to base10 inc di ;Skip character
mov al, cl ;Set low-byte to cl call todec ;Convert to base10 inc di ;Skip character
mov al, dh ;Set low-byte to dh call todec ;Convert to base10 inc di ;Skip character
mov al, dl ;Set low-byte to dl call todec ;Convert to base10
mov dx, offset date_str ;Now load offset of the date_str string into dx call print ;And print the (modified) string
mov dx, offset time_str ;Load offset of the time_str string into dx call print ;And print the (modified) string
mov ax, 4C00h ;Do a clean exit(error code=00) int 21h
;=================================================================== ;todec - converts the contents of ax into base10 ascii character(s) ; of length bx ; min_size defines minimum length of result, and padd_char ; defines the padding character. ;The result(s) are stored at ds:di ;=================================================================== todec proc push ax ;Save all registers push bx push cx push dx
xor cx,cx ;Empty the POP counter mov bx,10 ;Base divisor decloop: xor dx,dx ;Set the high 16-bits to 0 div bx ;Preform division(dx=remainder, ax=quotient) inc cx ;Increase the counter push dx ;and save the remainder cmp ax,0 ;If the quotient != 0 jnz decloop ;then get one more number
mov bx, [min_size] ;Load min_size value into bx mov dl, [padd_chr] ;Load padd_chr value into dl padd_result: cmp cx, bx ;Is cx >= min_size? jge poploop ;If so, proceed
本文章更多内容:1 - 2 - 下一页>> |