1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
| datasg segment outstr1 db 0dh,0ah,'please input the first number(0-99):',0dh,0ah,'$' outstr2 db 0dh,0ah,'please input the second number(0-99):',0dh,0ah,'$' outstr3 db 0dh,0ah,'input an invalid number, input again!',0dh,0ah,'$' endstr db 0dh,0ah,'$' instr1 db 3 db ? db 3 dup(0) instr2 db 3 db ? db 3 dup(0) a dw ? b dw ? nozero db 0 datasg ends stacks segment dw 256 dup(?) stacks ends
codesg segment assume cs:codesg, ds:datasg, ss:stacks start: mov ax, stacks mov ss, ax mov ax, datasg mov ds, ax mov ah, 09h mov dx, offset outstr1 int 21h input1: mov ah, 0ah mov dx, offset instr1 int 21h
mov si, offset instr1 call judgeNum and dl, dl jnz next1
mov ah, 09h mov dx, offset outstr3 int 21h jmp input1 next1: mov si, offset instr1 call transToNum mov a, ax
mov ah, 09h mov dx, offset outstr2 int 21h input2: mov ah, 0ah mov dx, offset instr2 int 21h
mov si, offset instr2 call judgeNum and dl, dl jnz next2
mov ah, 09h mov dx, offset outstr3 int 21h jmp input2 next2: mov si, offset instr2 call transToNum mov b, ax
mov ax, a mul b push ax mov dx, offset endstr mov ah, 09h int 21h pop ax
push ax test ax, ax jnz printNormal push ax mov ah, 02h mov dl, '0' int 21h pop ax jmp next3 printNormal: mov bx, ax mov cl, 8 shr bx, cl call printHex mov bx, ax and bx, 00ffh call printHex next3: mov ah, 02h mov dl, 'H' int 21h mov ah, 09h mov dx, offset endstr int 21h
mov nozero, 0 pop ax push ax
test ax, ax jnz printNormal2 mov ah, 02h mov dl, '0' int 21h jmp next4 printNormal2: mov bx, ax call printBin next4: mov ah, 02h mov dl, 'B' int 21h mov ah, 09h mov dx, offset endstr int 21h
pop ax call printDec mov ah, 02h mov dl, 'D' int 21h mov ah, 09h mov dx, offset endstr int 21h
mov ah, 4ch int 21h
judgeNum proc add si, 2 mov dl, [si] cmp dl, '0' jb false cmp dl, '9' ja false
cmp byte ptr [si - 1], 1 jz then
mov dl, [si + 1] cmp dl, '0' jb false cmp dl, '9' ja false mov dl, 1 jmp then false: mov dl, 0 then: ret judgeNum endp
transToNum proc push dx mov ax, 0h add si, 2 mov al, ds:[si] and al, 0fh cmp byte ptr [si - 1], 1 jz then2
mov dl, 10 mul dl mov dl, ds:[si + 1] and dl, 0fh add al, dl then2: pop dx ret transToNum endp
transToASCII proc push ax or dl, 30h cmp dl, 39h jbe output add dl, 7 output: mov ah, 2 int 21h pop ax ret transToASCII endp
printHex proc push ax push bx push cx push bx mov dl, bl mov cl, 4 shr dl, cl
mov bl, dl test bl, bl jnz goTrans and nozero, 1 jz nextstep goTrans: mov nozero, 1 call transToASCII nextstep: pop dx and dx, 000fh mov bl, dl test bl, bl jnz goTrans2 and nozero, 1 jz nextstep2 goTrans2: mov nozero, 1 call transToASCII nextstep2: pop cx pop bx pop ax ret printHex endp
printBin proc push ax push cx push dx mov ax, 8000h again: test bx, ax jz moveZero mov dl, '1' mov nozero, 1 jmp printNum moveZero: mov dl, '0' printNum: and nozero, 1 jz thus push ax mov ah, 02h int 21h pop ax thus: shr ax, 1 test ax, ax jnz again pop dx pop cx pop ax ret printBin endp
printDec proc push bx push cx push dx mov cx, 0 mov bx, 10D mov dx, 0 goDivide: inc cx mov dx, 0 div bx push dx test ax, ax jnz goDivide goOutput: pop dx or dl, 30h mov ah, 02h int 21h loop goOutput
pop dx pop cx pop bx ret printDec endp codesg ends end start
|