Assembly Language Homework Project (Two)
来源:互联网 发布:太原理工软件学院几本 编辑:程序博客网 时间:2024/06/05 01:00
Assembly Language Homework Project (Two)
键盘输入两个十进制非符号数(≤65535),计算两数之乘积,分别以十进制、十六进制、二进制输出结果。例如:
输入:
12345
65535输出:
12345*65535=
809029575
3038CFC7h
0011 0000 0011 1000 1100 1111 1100 0111B
.386data segment use16 buf db 7, 0, 7 dup(0);input the number s db 20 dup(0);output the formula p db 40 dup(" "), 0Dh, 0Ah, '$';output the decimal result m db 40 dup(" "), 0Dh, 0Ah, '$';output the hexadecimal result n db 40 dup(" "), 0Dh, 0Ah, '$';output the binary resultdata endscode segment use16assume cs:code, ds:datamain: mov ax, data mov ds, ax mov si, 0 call input call convert push ax call newline mov s[si],'*' inc si call input call convert mov s[si], '=' inc si mov s[si], '$' mov dx, 0 mov bx, ax pop ax mul bx;ax is multipled by bx ;the result:dx:ax = high 16 digits : low 16 digits call output call outputdec call outputH call outputB mov ah, 4Ch int 21h;------Convert------------------------------;Goal: To convert strings to numbers;Way : Use the multiplication;Parameter: buf, sconvert: mov bx, 2 mov ax, 0 mov dx, 0 next: mov dl, buf[bx] cmp dl, 0Dh je done imul ax, ax, 10 mov s[si], dl sub dl, '0' add ax, dx inc bx inc si jmp next done: ret;------End of Convert----------------------;------Output------------------------------output: push ax push dx mov ax, 0 mov dx, 0 call newline mov dx, offset s mov ah, 09h int 21h pop dx pop ax ret;------End of Output-----------------------;------Outputdec---------------------------;Goal: To output the decimal result;Way : Use the division;Example: 123 -> 123%10 -> 3; 12 -> 12%10 -> 2 ; 1 -> 1%10 -> 1 ; stack: 123outputdec: push ax push dx mov ah, 2 mov dl, 0Dh int 21h mov ah, 2 mov dl, 0Ah int 21h pop dx pop ax push ax push dx xor cx, cx xor di, diagain: push cx mov cx, 10 call divdw pop cx add dl, '0' push dx mov dx, bx inc cx cmp ax, 0 jne againpop_again: pop dx mov p[di], dl inc di dec cx jnz pop_again mov ah, 09h mov dx, offset p int 21h pop dx pop ax ret;------End of Outputdec--------------------;------OutputH-----------------------------;Goal: To output the hexademical result;Way : Use the shift;Example: 7FFFh -> FFF7h And 000Fh -> 7; FFF7h -> FF7Fh And 000Fh -> F; FF7Fh -> F7FFh And 000Fh -> F; F7FFh -> 7FFFh And 000Fh -> F; result: 7FFFhoutputH: push ax push dx push ax mov ax, dx mov cx, 4 mov bx, 2 mov di, 0again1: push cx mov cl, 4 rol ax, cl push ax and ax, 000Fh cmp ax, 10 jb is_digitis_alpha: sub al, 10 add al, 'A' jmp finish_4bitsis_digit: add al,'0'finish_4bits: mov n[di], al pop ax pop cx inc di dec cx jnz again1 dec bx cmp bx, 0 je next1 mov cx, 4 pop ax jmp again1next1: mov n[di],'h' mov ah, 9 mov dx, offset n int 21h pop dx pop ax ret;------End of OutputH------------------;------OutputB-------------------------;Goal: To output the binary result;Way : Use the shfit;Example: 1011B -> 0111B And 0001h -> 1; 0111B -> 1110B And 0001h -> 0; 1110B -> 1101B And 0001h -> 1; 1101B -> 1011B And 0001h -> 1; result: 1101BoutputB: push ax mov ax, dx mov cx, 10h mov di, 0 mov bx, 2 mov si, 4again2: push cx mov cl, 1 rol ax, cl push ax and ax, 0001h add al, '0' mov m[di], al pop ax pop cx inc di dec si cmp si, 0 jne continue inc di mov si, 4 continue: dec cx jnz again2 dec bx cmp bx, 0 je next2 mov cx, 10h pop ax jmp again2next2: dec di mov m[di], 'B' mov ah, 9 mov dx, offset m int 21h ret;------End of OutputB------------------;------Divdw---------------------------;Goal: To solve the problem---overflow;Way : Use the formula; X/N=int(H/N)*65535+[rem(H/N)*65535+L]/N;Parameter :dividend: dx:ax = high 16 digits : low 16 digits; divisor : cx;;Return :quotient : bx = high 16 digits ax = low 16 digits; :remainder: dxdivdw: push ax mov ax, dx xor dx, dx div cx mov bx, ax pop ax div cx ret;------End of Divdw--------------------;------Newline-------------------------;Use int 21h ah=02h;Output '\n'newline: mov ah, 02h mov dl, 0Dh int 21h mov ah, 02h mov dl, 0Ah int 21h ret;------End of Newline-------------------;------Input---------------------------- input: mov ah, 0Ah mov dx, offset buf int 21h ret;------End of Input---------------------code endsend main
问题:
- 32位寄存器的除法应该如何实现
- push pop 为什么会出问题
- dx,ax如何存入eax
- 除法为什么会死循环
0 0
- Assembly Language Homework Project (Two)
- assembly language
- assembly language
- Assembly Language Reference
- Assembly language experiment----Encryption
- x86 Assembly Language
- Professional Assembly Language
- Professional.Assembly.Language
- Assembly language Start
- begin assembly language
- 汇编语言Assembly Language
- 什么是 .NET Assembly language?
- arm assembly language
- assembly language programm--HelloWorld
- New job,Assembly Language
- Assembly Language Debugger(ALD)
- Assembly Language Note(1)
- Assembly Language(汇编语言)概述
- Docker Hub与Docker Store详解
- java中HashMap详解
- JavaScript学习-DOM扩展_专有扩展
- HIT训练
- uboot源码分析二
- Assembly Language Homework Project (Two)
- ios开发之Swift获取视频截图(本地视频、网络视频的缩略图)(转)
- Guava学习笔记目录
- 类与类之间的关系
- while(TI == 0);TI = 0;
- Guava学习笔记【1】:Google Guava 类库简介
- Guava学习笔记【2】:Optional优雅的使用null
- Java面试大全(一)
- Guava学习笔记【3】:Preconditions优雅的检验参数