⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 汇012.txt

📁 会变语言实现的一些程序
💻 TXT
📖 第 1 页 / 共 2 页
字号:
 locate(row, col);
 in.r_ds = FP_SEG(string); in.r_dx = FP_OFF(string); in.r_ax = 0x900; intr(0x21, &in);
 locate(x, y);
}

  check_key_state()  /* 在(row, col)位置以属性attr显示字符ch */ 

{char state;

 state = bioskey(2);
 if (state & CAPS_KEY)
  {if (!cap_key) {cap_key = 1; disp_string(24, 66, "CAP$");}
  }
else if (cap_key) {cap_key = 0; disp_string(24, 66, " $");}
if (state & NUM_KEY)
 {if (!num_key) {num_key = 1; disp_string(24, 70, "NUM$");}
 }
else if (num_key) {num_key = 0; disp_string(24, 70, " $");}
}

  insert_key()  /* 在最后一行显示插入/修改状态标志,并改变光标形状 */ 

{union REGS in, out;

 insert = 1 - insert;
 disp_string(24, 74, (insert ? "INS$" : " $"));  /* 显示插入/修改标志 */
 in.h.ah = 1;
 in.h.ch = (insert ? 0 : 14); in.h.cl = 15;    /* 改变光标的形状 */
 int86(0x10, &in, &out);
}

  move_right(int row, int col, int len)  /* 在(row, col)位置之后的字符和属性向后移len个位置 */ 

{int j, attr;
 char ch;

 for (j = 79; j >= col+len; j--)
  {read_char_attr(row, j-len, &ch, &attr);
   write_char_attr(row, j, ch, attr);
  }
}

  read_char_attr(int row, int col, char *ch, int *attr)  /* 在读(row, col)位置字符和属性,并分别存入ch和attr */ 

{union REGS in, out;

 locate(i, j);
 in.h.ah = 8; in.h.bh = 0;
 int86(0x10, &in, &out);
 *ch = out.h.al; *attr = out.h.ah;
}

  write_char_attr(int row, int col, char ch, int attr)  /* 在(row, col)位置以属性attr显示字符ch */ 

{union REGS in, out;

 locate(row, col);
 in.h.ah = 9; in.h.al = ch;
 in.h.bh = 0; in.h.bl = attr; in.x.cx = 1;
 int86(0x10, &in, &out);
}

  ctos(char ascii, char str[])  /* 把字符的ASCII码转换成字符串 */ 

{int i;

 i = 2;
 do {str[i--] = ascii%10 + '0';
  ascii /= 10;
 } while (ascii > 0);
 for (; i >= 0; i--) str[i] = ' ';
}

main()
{int k, key, row, col;
 char ch1, ch2, str[]=" $";   /* 前面有3个空格 */
 char msg1[]="This is a simple screen edidtor.$",
 msg2[]="You can move cursor by Arrow keys, TAB/Shift-TAB, Home and End.$",
 msg3[]="You can press ^W for scroll up or ^Z for scroll down.$",
 msg4[]="It has some functions, such as insert/modify a char.$",
 msg5[]="If you press a function key, or key combined with Alt, Ctrl, Shift, it will display the key's scan code.$",
 msg6[]="The program exits when you press ESCAPE.$"; 

cls(UP_SCROLL, 0, 0, 24, 79, 0, 7);
disp_string(0, 0, msg1); disp_string(2, 0, msg2);
disp_string(4, 0, msg3); disp_string(6, 0, msg4);
disp_string(8, 0, msg5); disp_string(11, 0, msg6);
row = col = ch1 = insert = 0;
locate(row, col); 

while (ch1 != ESCAPE)
 {while (ch1 != ESCAPE)
  {if (!bioskey(1)) {check_key_state(); continue;}
   key = bioskey(0);
   ch1 = key; ch2 = key >> 8;
   if (ch1 != 0)
    {switch(ch1)
    {case TAB_KEY:
        col = ((col&0xFFF8) + 8) %80;
        break;
    case CTRL_W:
       cls(DOWN_SCROLL, 0, 0, 24, 79, 1, 7);
       row = row + 1;
       break;
    case CTRL_Z:
       cls(UP_SCROLL, 0, 0, 24, 79, 1, 7);
       break;
    default:
       if (ch1 == ESCAPE) continue;
       if (insert) move_right(row, col, 1);
       write_char_attr(row, col, ch1, 31);
       col = (col+1+80) % 80;
       break;
   }
   locate(row, col);
   continue;
   } 

switch (ch2)
 {case UP_ARROW:
    row = (row-1+25) % 25;
    break;
  case DOWN_ARROW:
    row = (row+1+25) % 25;
    break;
  case LEFT_ARROW:
    col = (col-1+80) % 80;
    break;
  case RIGHT_ARROW:
    col = (col+1+80) % 80;
    break;
  case SHIFT_TAB:
    k = col & 0xFFF8;
    col = (col - ((k==0)? 8:k+80)) % 80;
    break;
  case HOME_KEY:
    col = 0;
    break;
  case END_KEY:
    col = 79;
    break;
  case INSERT:
    insert_key(&insert);
    break;
  default:
    ctos(ch2, str);
    k = strlen(str)-1;
    if (insert) move_right(row, col, k);
    disp_string(row, col, str);
    col = (col + k + 80) % 80;
    break;
 } 

  locate(row, col);
  }
 }
 cls(UP_SCROLL, 0, 0, 24, 79, 0, 7);
} 
12.4 习题
12.1、把12.3节中的C语言程序改写成汇编语言程序。
 
12.2、编写C语言程序,输出下面表达式的值,要求该表达式的计算用嵌入汇编语言程序段的方法来实现(注:题中所有变量都是整型)。
 
1)、1230 + 'A' - a
2)、b * b – 4 * a * c
3)、(a + b) / c + d
 4)、9*c / 5 + 32
5)、(a % 9 + 89) * 8
6)、x * x + y * y 
12.3、用汇编语言编写函数Display(Data),其功能是在当前光标处显示无符号整数Data,然后,编写一个C语言程序调用Display来显示整型变量的值。
 
12.4、用汇编语言实现下列C语言标准函数,并在C语言程序中验证之(假设未指明的变量都是整型)。
 
1)、isalpha(int Ascii) /*若Ascii是字母的Ascii码,则其函数值为真,否则为假*/
 
2)、isxdigit(int Ascii)
/*若Ascii是十六进制字符('0'~'9'、'A'~'F'和'a'~'f'),那么,其函数值为真,否则为假*/
 
3)、strlwr(char *s) /*把字符串s中的字母转换成小写*/
 
4)、strchr(char *s1, int Ascii)
/*在字符串s1中查找是否存在字符Ascii。若不存在,则返回NULL(即0),否则,返回指向该字符在字符串中位置的指针*/
 
5)、strncmp(char *s1, char *s2, int Len)
/*比较字符串s1和s2前Len个字符,若s1<s2,其值小于0;s1==s2,其值为0;否则,其值大于0*/
 
6)、strncpy(char *Dest, char *Src, int Len) /*把Src串中前Len个字符拷贝到Dest中*/
 
7)、memset(void *Buff, int Data, int Len)  /*把用Data填充Buff前Len个存储单元*/
 
12.5、编写一个C语言程序,用TCC/BCC命令生成汇编语言程序,分析C语言语句和汇编语言语句之间的实现关系。
 
12.6、编写一个C语言程序,求出2~100之内的所有素数(大于1,且只能被1和自身整除的数,称为素数),然后把它改写汇编语言程序,并比较二者代码的。
 
12.7、编写一个C语言程序,求出2~999之内的所有能被9整除,且含有5的数,然后把它改写汇编语言程序。
 
12.8、用汇编语言编写一个过程Display(Data),其功能为在当前光标处显示无符号整数Data,然后编写C语言程序调用之,以达到显示数据的作用。
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -