- Assembly code
;------------------------------------------------------------------------------------;Description:To output a value to screen in the hexadecimal form;Author: ;creat date:2007-11-18;modify date:;Algorithms: 1 首先判断数据是否小于0,若小于0,首先在屏幕上输出一个字符'0'。; 2 AX,BX同时保存这个数据,BX与1111B相与,结果是BX中只保留下最低4位,即我们要的数字; 若数字大于9,则BL-10+'a',但到其16进制的字符,否则BL+'0'也得到其16进制最低位的字符; 3 AX循环右移4位,再Mov bx,ax,重复2的步骤至所有的4个4 bits的数据都取到;------------------------------------------------------------------------------------ data1 segment ; Please input here the code of data segment val dw -78 msg db 4 dup(?),'H',13,10,'$'data1 endsstack1 segment ;Please input here the code of data segmentstack1 endscode1 segment assume cs:code1,ds:data1,ss:stack1start: mov ax,data1 mov ds,ax ;Please input here the code of code segment mov ax,[val] cmp ax,0 jl prezero ; If the val is less than 0, output a zero first contin: mov ax,[val] ; If ax<0, the prezero will overwrite ax, so we reset it to make sure it is proper mov cx,3 pro: mov si,offset msg add si,cx mov bx,ax and bx,1111b ; logical and make the higher 4 bits zero, only leave the lower 4 bits cmp bl,10 jge hexad ; if the lower 4 bits is great or equal to 10, jump to set letter adcx: ; if the lower 4 bits is not great or equal to 10, go down to set number's ASCII add bl,'0' mov byte ptr [si],bl jmp shad ; jump to decrement cx, and shift right of ax hexad: ; The following fragment process the hexadecimal letter sub bl,10 add bl,'a' mov byte ptr [si],bl shad: dec cx cmp cx,0 jl quit ROR ax,4 ;Shift ax 4 bits right jmp proprezero: mov dl,'0' mov ah,2 int 21h jmp contin quit: mov ah,9 mov dx,offset msg int 21h mov ah,4ch int 21hcode1 ends end start
上面上显示一个数的16进制的形式的。
我写的这个程序在未来汇编编译一点问题都没有,但在MASM6.15就说有问题~~
- Assembly code
0031 shad: ;**.lst里面的信息 0031 49 dec cx 0032 83 F9 00 cmp cx,0 0035 7C 0A jl quit ROR ax,4 ;Shift ax 4 bits rightval2hex.asm(60) : error A2070: invalid instruction operands 0037 EB DA jmp pro
我也不知用Masm6.15行不行,因为学校只学16位的汇编,我现在也在看Assembly language for Intel-based computers fourth edition,里面只要是32位汇编的,跟着里面的说明做后,再设回我以前Masm6.11的环境变量也不行了。真不知怎样的,麻烦各位帮我解释下。
在这里谢了!!!
------解决方案--------------------------------------------------------
- Assembly code
ROR ax,4 ;Shift ax 4 bits right