新手求助

wk8023xy 2011-12-22 07:56:03
一个96位的二进制数,分三部分分别存储在 eax, ebx, ecx。怎么转化为96位二进制对应的十进制输出?
...全文
89 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangbch 2011-12-27
  • 打赏
  • 举报
回复
先给出所有源代码
#include "stdio.h"
#include "stdlib.h"

typedef unsigned long DWORD;

//pn[0], the lowest 32bits
//pn[1], the middle 32bits
//pn[2], the highest 32bits

void uint96_to_string(DWORD *pn, char *szString)
{
_asm
{
push esi
push edi
push ecx

mov esi,pn
mov edi,szString
mov ecx,10
jmp check_n

div_h_32bit:
mov eax,dword ptr [esi+8]
div ecx
mov dword ptr [esi+8], eax

div_m_32bit:
mov eax,dword ptr [esi+4]
div ecx
mov dword ptr [esi+4], eax

div_l_32bit:
mov eax,dword ptr [esi]
div ecx
mov dword ptr [esi], eax

add dl,'0'
mov byte ptr [edi],dl
inc edi

check_n:
xor edx,edx
cmp [esi+8],0
jnz div_h_32bit

cmp [esi+4],0
jnz div_m_32bit

cmp [esi],0
jnz div_l_32bit

//now, the whole 96bit number is full 0
cmp edi,szString
jne invert_n

//if uint96 is 0, then edi == szString, in this case, we need put '0' to szString and return
mov byte ptr [edi],'0' //put 0 to buffer
mov byte ptr [edi+1],0 //c language string terminating symbol
jmp thisExit

invert_n:
mov byte ptr [edi],0 //c language string terminating symbol
dec edi //the edi point to the tail of string
mov esi,szString //the esi point to the head of string
jmp invert_cmp

invert_loop:
mov al,[esi]
mov dl,[edi]
mov [edi],al
mov [esi],dl
inc esi
dec edi

invert_cmp:
cmp esi,edi
jb invert_loop
thisExit:
pop ecx
pop edi
pop esi
}

}

void test_uint96_to_string()
{
DWORD n[3];
char result[32];
int case_id=1;

//case 1:
n[0]=0;
n[1]=0;
n[2]=0;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 2:
n[0]=9;
n[1]=0;
n[2]=0;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 3:
n[0]=10;
n[1]=0;
n[2]=0;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 4:
n[0]=0xffffffff;
n[1]=0;
n[2]=0;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 4:
n[0]=0;
n[1]=1;
n[2]=0;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 6:
n[0]=1;
n[1]=1;
n[2]=0;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 7:
n[0]=0;
n[1]=0;
n[2]=1;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 8:
n[0]=1;
n[1]=0;
n[2]=1;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;

//case 9:
n[0]=0xffffffff;
n[1]=0xffffffff;;
n[2]=0xffffffff;;
uint96_to_string(n,result);
printf("run case %d,result is %s\n",case_id,result);
case_id++;


}

int main(int argc, char* argv[])
{
test_uint96_to_string();
}
liangbch 2011-12-27
  • 打赏
  • 举报
回复
更正,“此文件嵌入式的汇编代码的函数”应该是 “c文件嵌入式的汇编代码的函数”
liangbch 2011-12-27
  • 打赏
  • 举报
回复
你的开发环境是VC吗?如果是我给你写一个此文件嵌入式的汇编代码的函数。
zara 2011-12-23
  • 打赏
  • 举报
回复
这个,是有些麻烦。进制转换输出结果,一般都是采用循环除 10 得余数直至 0 再逆序输出余数(对十进制来说)。超出当前位数表示的数值的输出,就涉及到超长类数运算方面的算法或技巧了;这方面,上面那段代码的主人应该是颇为擅长的。
wk8023xy 2011-12-23
  • 打赏
  • 举报
回复
。。。关键是那位代码的主人不在啊,真有点头疼了!给他说话也没回,着急。。。
wk8023xy 2011-12-22
  • 打赏
  • 举报
回复
这个东西这么复杂啊,有点看不懂
zara 2011-12-22
  • 打赏
  • 举报
回复
这个,算法上可以参考http://topic.csdn.net/u/20111213/01/7b9809be-1061-4bd3-9fce-b32cadcb66e3.html这个帖子的 #4楼 里那个 output_num 子程,虽然它处理的是 2 个单元,但这个方法可以扩展到任意长度的数据。
wk8023xy 2011-12-22
  • 打赏
  • 举报
回复
这个是32位的,96位岂不是更麻烦?
masmaster 2011-12-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wk8023xy 的回复:]
打不开啊
[/Quote]
帮你搬过来

;conver a number result to output_buffer and fill '$' after number string
;function:
; conver 32 bit integer result to string
;input parameter:
; none, always convert varible result

;output parameter
; di: The address of output buffer

output_num proc
push di ;di is the address of out_buff
mov bx,10

convert_high:
xor dx,dx
mov ax,word ptr [result+2]
div bx
mov word ptr [result+2],ax

convert_low:
mov ax,word ptr [result]
div bx
mov word ptr [result],ax

add dl,'0' ;save (result % 10)+'0' to out_buffer
mov byte ptr [di],dl
inc di ;di point next position

cmp_r:
cmp word ptr [result+2],0
jnz convert_high

mov dx,0
cmp word ptr [result],0
jnz convert_low

inv_string: ;swap string head and string tail
pop si ;now si is the address of out_buff
dec di ;the di point to the last char
mov bx,di
inv_loop:
mov al,[si] ;swap char
mov ah,[di]
mov [di],al
mov [si],ah
inc si
dec di
cmp_head_tail:
cmp si,di
jb inv_loop

mov byte ptr [bx+1], '$' ; For dos ah=09, string output, the terminal char must be '$'
ret
output_num endp
wk8023xy 2011-12-22
  • 打赏
  • 举报
回复
打不开啊
新手求助RBF神经网络数据预测问题-数据.xls 本程序用前六个数据预测下一数据,前200组数据用于训练,用后80组数据进行预测,可预测结果为一个值,请大家指教: 源程序为: clc clear close all %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %每五个数据整合, x=xlsread; n=length m=5; sum=0; j=1; x1=zeros); for k=1:m:n     for i=k:         sum=sum x;     end     x1=sum;     j=j 1;     sum=0; end j t=1:; figure plot;%,'d-m' hold on; grid on title; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %归一化处理 [x2,mint,maxt] = premnmx figure plot;%,'d-m' hold on; grid on title; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %输入数据 for k=1:1:200     p_train=[x2 x2 x2 x2 x2 x2]; 5*6     t_train=x2; 5*1 end     p_train=p_train'; %6*195     t_train=t_train'; %1*195 for z=1:1:81     p_test=[x2 x2 x2 x2 x2 x2];     t_test=x2; end      p_test=p_test';      t_test=t_test'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %建立 RBF 网络                      goal = 0.0001;                     % 训练误差的平方和 spread = 0.01;                     % 此值越大,需要的神经元就越少 MN = size;              % 最大神经元数 DF = 1;                            % 显示间隔 net = newrb; data_out=sim p_mse=mse figure plot hold on plot title; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %预测并作图 y=sim y_mse=mse figure plot; hold on; plot title; legend;
新手求助RBF神经网络数据预测问题-历史开奖数据.xlsx 本程序用前六个数据预测下一数据,前200组数据用于训练,用后80组数据进行预测,可预测结果为一个值,请大家指教: 源程序为: clc clear close all %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %每五个数据整合, x=xlsread; n=length m=5; sum=0; j=1; x1=zeros); for k=1:m:n     for i=k:         sum=sum x;     end     x1=sum;     j=j 1;     sum=0; end j t=1:; figure plot;%,'d-m' hold on; grid on title; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %归一化处理 [x2,mint,maxt] = premnmx figure plot;%,'d-m' hold on; grid on title; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %输入数据 for k=1:1:200     p_train=[x2 x2 x2 x2 x2 x2]; 5*6     t_train=x2; 5*1 end     p_train=p_train'; %6*195     t_train=t_train'; %1*195 for z=1:1:81     p_test=[x2 x2 x2 x2 x2 x2];     t_test=x2; end      p_test=p_test';      t_test=t_test'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %建立 RBF 网络                      goal = 0.0001;                     % 训练误差的平方和 spread = 0.01;                     % 此值越大,需要的神经元就越少 MN = size;              % 最大神经元数 DF = 1;                            % 显示间隔 net = newrb; data_out=sim p_mse=mse figure plot hold on plot title; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %预测并作图 y=sim y_mse=mse figure plot; hold on; plot title; legend;

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧