Hex to Decimal 0 9 - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Hex to Decimal 0 9

Description:

Hex to Decimal 0 - 9 .model tiny .stack .data .code. hex2dec: sub ax,ax ... ret. end. Computer Organization and Assembly Language #3. C. Vongchumyen 12 / 2003 ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 34
Provided by: kmit
Category:
Tags: decimal | hex | ret

less

Transcript and Presenter's Notes

Title: Hex to Decimal 0 9


1
Hex to Decimal 0 - 9
.model tiny .stack .data .code hex2dec sub ax,ax
mov al,Hex hex value between
0-F cmp al,0ah jc less_than_10 add ax,3026h
inc ah ret less_than_10 add ax,
3030h ret end
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
2
ASCII Chart
30H 0 31H 1 32H 2 33H
3 34H 4 35H 5 36H 6 37H
7 38H 8 39H 9 30H 0
41H A 42H B 43H C 44H
D 45H E 46H F
61H a 62H b 63H c 64H
d 65H e 66H f
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
3
Hex to Decimal 00 - 99
.data string db "00",'' .code val2str mov
ax,_at_data mov ds,ax sub ax,ax mov al,078
value between 0-99 mov bl,10 div bl al ax
div bl ah ax mod bl add al,30h 30h
'0' add ah,30h mov si,offset
string mov si,al mov si1,ah can use
mov si,ax ret end
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
4
Define Directive
DB Define Byte DW Define Word DD Define
Double Word DQ Define Quad Word DT Define
Ten Bytes Word string db "00",' 0, 0,
in each byte Num dw 1234h
1234h in memory Array db 12h, 34h 12h and
34h in memory XX db 20 dup (0) XXX db 20 dup
(?)
C. Vongchumyen 12 / 2003
5
Adding by BCD Technique
CX DX BX in BCD Format mov dx,1234h load
1,234 mov bx,3099h load 3,099 mov al,bl
sum BL with DL add al,dl 34 99 CDh
(133) daa adjust to 1 and 33 mov cl,al
answer to CL mov al,bh sum BH, DH and
Carry adc al,dh 12 30 Carry
43 daa adjust to 0 and 43 mov ch,al
answer to CH answer is 4333
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
6
DAA
?????? DAA ????????????????????????????   if (
(AL and 0Fh) gt 9 or (AuxC 1)) then al al
6 AuxC 1 Set Auxilliary carry. endif if (
(al gt 9Fh) or (Carry 1)) then al al
60h Carry 1 Set carry flag. Endif
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
7
DAS
?????? DAS ???????????????????? DAA
?????????????????????? Sub ???? Sbb
???????????????????   if ( (al and 0Fh) gt 9 or
(AuxC 1)) then al al -6 AuxC 1 endif if
(al gt 9Fh or Carry 1) then al al - 60h Carry
1 Set the Carry flag. Endif
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
8
AAA
????????????????????? ASCII ??????????????????
ASCII ???? 31h39h ????????????? 6Ah ???????
0100h (1 9 10) mov ax,31h Ascii
1 add al,39h Ascii 9 aaa adjust to
0100h add ax,3030h Convert to Ascii 3130h
(10)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
9
BCD to ASCII
.data string db "00",'' .code mov ax,_at_data
load data segment to ds mov ds,ax mov si,offset
string point si to string sub ax,ax mov dl,Nu
mber(h) value to convert mov al,dl and al,0f
h do on low nibble first add si1,al
save to memory in ASCII format mov al,dl and
al,0f0h do on high nibble mov bl,10h
div by 10 div bl add si,al
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
10
Multiply by Shift
Multiply 10 shl ax,1 shift left X
2 mov bx,ax save to bx shl ax,2 shigt left
twice again X 8 ( X 4 X 2 ) add ax,bx
add X 2 with X 8 X 10
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
11
Jump
if ax gt bx then mov cx,ax else mov cx,bx   ????
??????????????????????????   cmp ax,bx jbe els
e mov cx,ax jmp short endif else mov cx,bx e
ndif
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
12
For Loop
for I 1 to 10 do a a 1   ???????????????
???? a db 0 ... mov cx,1 count cmp cx,10
je over inc a inc cx jmp count over
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
13
For Loop (New one)
for I 1 to 10 do a a 1   ???????????????
????????????????????????????????????????????
????   a db 0 ... mov cx,10 count inc a
loop count
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
14
Basic Dos Function
Name Terminate a process (EXIT) Function 4Ch
(76) On Entry AH 4Ch AL Exit
code Return Nothing Description return to DOS
with exit code in al and can be test by
ERRORLEVEL in DOS
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
15
Basic Dos Function
Mov ah,4ch call function 4ch Mov al,00h
return 00 Int 21h call software interrupt
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
16
Basic Dos Function
Name Character Output Function 02h (2) On
Entry AH 02h DL Character Return Nothing
Description Print a character in dl to stand
output device (screen)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
17
Basic Dos Function
Mov ah,02h call function 02h Mov dl,_at_ print
_at_ Int 21h call software interrupt
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
18
Basic Dos Function
Name Print String Function 09h (9) On
Entry AH 09h DSDX Pointer to Character
String Return Nothing Description Print string
that point by DSDX, String must be terminate
with
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
19
Basic Dos Function
.data String db Hello world,
.code mov ax,_at_data load ds with String
segment mod ds,ax mov ah,09h call function
09h mov dl,_at_ print _at_ int 21h call
software interrupt
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
20
Basic Dos Function
Name Read Keyboard Character and Echo Function
01h (1) On Entry AH 01h Return AL
Character to read Description Read character
from standard input device and echo to standard
output device. Special key is return 0, call this
function again to get scan code. Wait for key if
not keypressed.
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
21
Basic Dos Function
.data Key db ? .code mov ax,_at_data load ds
segment mov ds,ax mov ah,01h call function
01h int 21h Wait a key mov Key,al save
key read, return in al
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
22
Basic Dos Function
Name Read Keyboard Character Without
Echo Function 08h (8) On Entry AH 08h
Return AL Character to read Description Rea
d character from standard input device WITHOUT to
standard output device. Special key is return 0,
call this function again to get scan code. Wait
for key if not keypressed.
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
23
Basic Dos Function
.data Key db ? .code mov ax,_at_data load ds
segment mov ds,ax mov ah,01h call function
01h int 21h Wait a key mov Key,al save
key read, return in al
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
24
Basic Dos Function
Name Buffered Input Function 0Ah (10) On
Entry AH 0Ah DSDX Pointer to an input
buffer offset 0 specific max buffer
length Return AL Character to
read DSDX String input offset 1 actual
length receive exclude enter Description Read
a string from keyboard until the ENTER key is
pressed.
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
25
Basic Dos Function
.data MaxStr db 20 ActualStr db ? String db 20
dup(?) .code mov ax,_at_data load data
segment mov ds,ax mov ah,0ah function
number lea dx,MaxStr load buffered input
address int 21h call interrupt
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
26
Basic Dos Function
Name Get System Date Function 2Ah (42) On
Entry AH 2Ah Return AL Day of week ( 0
6 ), 0 Sunday CX Year ( 1980 - 2099
) DH Month ( 1 - 12 ) DL Date ( 1 31
) Description Report a current system date
including day of week
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
27
Basic Dos Function
.data Day db ? Date db ? Month dw ? Year db ?
.code mov ax,_at_data load ds
segment mov ds,ax mov ah,2Ah call function
2Ah int 21h Get date mov Day,al save day
of week mov Date,dl save date mov Month,dh
save month mov Year,cx save year (1980)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
28
Basic Dos Function
Name Set System Date Function 2Bh (43) On
Entry AH 2Bh CX Year ( 1980 - 2099
) DH Month ( 1 - 12 ) DL Date ( 1 31
) Return AL 00 if valid date FF if not
valid date Description Set current system date,
No Day of week required
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
29
Basic Dos Function
mov ah,2Bh call function 2Bh mov dl,Date
set date mov dh,Month set month mov cx,Year
set year (1980) int 21h Set date
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
30
Basic Dos Function
Name Get System Time Function 2Ch (44) On
Entry AH 2Ch Return CH Hour ( 0 23
) CL Minutes ( 0 - 59 ) DH Seconds ( 0 -
59 ) DL Hundreds of second ( 0 99
) Description Report a current system time of
day, Most system accuracy is 1/18.2 not 1/100
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
31
Basic Dos Function
.data Hour db ? Minute db ? Second db ? Hundre
d db ? .code mov ax,_at_data load ds
segment mov ds,ax mov ah,2Ch call function
2Ch int 21h Get Time mov Hour,ch save
hour mov Minute,cl save minute mov Second,dh
save second mov Hundred,dl save hundred of
second
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
32
Basic Dos Function
Name Set System Time Function 2Dh (45) On
Entry AH 2Ch CH Hour ( 0 23 ) CL
Minutes ( 0 - 59 ) DH Seconds ( 0 - 59
) DL Hundreds of second ( 0 99
) Return AL 00 if set successfully FF
if set not successfully Description All register
format same as Get System time (2Dh)
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
33
Basic Dos Function
mov ah,2Dh call function 2Dh mov ch,Hour
set hour mov cl,Minute set minute mov dh,Second
set second mov dl,Hundred set hundred of
second int 21h Set date
C. Vongchumyen 12 / 2003
Computer Organization and Assembly Language 3
Write a Comment
User Comments (0)
About PowerShow.com