0

I have discovered a bug in some assembly code I have been working with but can't figure how to fix it. When shifting left by 0 the result ends up being 0 instead of jut the number. The same applies when shifting to the right. Any and all help is much appreciated.

function sal(n,k:integer):integer;
begin
 asm
 cld
  mov   cx,     k
@1:
  sal n, 1
  loop @1
 end;
 sal:= n;
end;

function sar(n,k:integer):integer;
begin
 asm
  cld
  mov   cx,     k
@1:
  sar   n,      1
  loop  @1
 end;
 sar:=n;
end;
2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by tr6699
0

I am not really an expert in assembly and haven't really used it much in the past few years. How would i go about doing that?

0

Okay, so I did what you said and I'm still getting the same errors

function sal(n,k:integer):integer;
begin
 asm
 cld
 mov    cx,     k
 jcxz @done
@1:
  sal n, 1
  loop @1
@done:
 end;
 sal:= n;
end;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.