最新Perl语言入门(第四版)习题答案
汇编语言程序设计(第四版)【课后答案】

汇编语言程序设计第四版【课后习题答案】第1章汇编语言基础知识〔习题1.1〕简述计算机系统的硬件组成及各部分作用。
〔解答〕CPU:包括运算器、控制器和寄存器组。
运算器执行所有的算术和逻辑运算;控制器负责把指指令逐条从存储器中取出,经译码分析后向机器发出各种控制命令,并正确完成程序所要求的功能;寄存器组为处理单元提供所需要的数据。
存储器:是计算机的记忆部件,它用来存放程序以及程序中所涉及的数据。
外部设备:实现人机交换和机间的通信。
〔习题1.2〕明确下列概念或符号:主存和辅存,RAM和ROM,存储器地址和I/O端口,KB、MB、GB和TB。
〔解答〕主存又称内存是主存储器的简称,主存储器存放当前正在执行的程序和使用的数据,CPU可以直接存取,它由半导体存储器芯片构成其成本高、容量小、但速度快。
辅存是辅助存储器的简称,辅存可用来长期保存大量程序和数据,CPU需要通过I/O接口访问,它由磁盘或光盘构成,其成本低、容量大,但速度慢。
RAM是随机存取存储器的英语简写,由于CPU可以从RAM读信息,也可以向RAM写入信息,所以RAM也被称为读写存储器,RAM型半导体存储器可以按地址随机读写,但这类存储器在断电后不能保存信息;而ROM中的信息只能被读出,不能被修改,ROM型半导体通常只能被读出,但这类存储器断电后能保存信息。
存储器由大量存储单元组成。
为了区别每个单元,我们将它们编号,于是,每个存储单元就有了一个存储地址,I/O接口是由一组寄存器组成,为了区别它们,各个寄存器进行了编号,形成I/O地址,通常称做I/O端口。
KB是千字节、MB是兆字节、GB是吉字节和TB是太字节,它们都是表示存储器存储单元的单位。
〔习题1.3〕什么是汇编语言源程序、汇编程序、目标程序?〔解答〕用汇编语言书写的程序就称为汇编语言源程序;完成汇编工作的程序就是汇编程序;由汇编程序编译通过的程序就是目标程序。
〔习题1.4〕汇编语言与高级语言相比有什么优缺点?〔解答〕汇编语言与高级语言相比的优点:由于汇编语言本质就是机器语言,它可以直接地、有效地控制计算机硬件,因而容易产生运行速度快,指令序列短小的高效目标程序,可以直接控制计算机硬件部件,可以编写在“时间”和“空间”两方面最有效的程序。
Perl练习题

2.12 练习写一个程序,计算半径为12.5的圆的周长。
圆周长等于2π(π约为3.1415926)乘以半径。
答案为78.5。
#!/usr/bin/perl$r=12.5;$pai=3.1415926 ;$C=2*$pai*$r;Print “$C\n”;修改上述程序,用户可以在程序运行时输入半径。
如果,用户输入12.5,则应得到和上题一样的结果。
#!/usr/bin/perl$r=<STDIN>;$pai=3.1415926 ;$C=2*$pai*$r;Print “$C\n”;修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。
#!/usr/bin/perl$r=<STDIN>;$pai=3.1415926 ;if($r>=0){$C=2*$pai*$r;}If($r<0){$C=0;}Print “$C\n”;写一个程序,用户能输入2 个数字(不在同一行)。
输出为这两个数的积。
#!/usr/bim/perl$a=<STDIN>;$b=<STDIN>;$c=$a*$b;Print”$c”;写一个程序,用户能输入1 个字符串和一个数字(n)(不在同一行)。
输出为,n 行这个字符串,1 次1 行(提示,使用“x”操作符)。
例如,如果用户输入的是“fred”和“3”,则输出为:3 行,每一行均为fred。
如果输入为“fred”和“299792”,则输出为299792 行,每一行均为fred。
#!/usr.bin/perl$string=<STDIN>;$int=<STDIN>;$output=$string x $intprint $output;3.9练习写一个程序,将一些字符串(不同的行)读入一个列表中,逆向输出它。
如果是从键盘输入的,那在Unix 系统中应当使用CTRL+D 表明end-of-file,在Windows 系统中使用CTRL+Z.写一个程序,读入一串数字(一个数字一行),将和这些数字对应的人名(下面列出的)输出来。
perl 复习题 (答案)

PERL复习题(答案不是标准答案,仅供参考)一、选择题1. What is the simplest type of data that Perl can work with?A elementB scalarC vectorD component2. Which operator can be used to take the bottom item from an array?A popB pushC pullD plant3. Which operator is used to arrange items in character order?A ascendB sortC arrangeD descend4. Rather than using print, what is often used in Perl when formatting is important?A printfB formatC alignD show5. Which modifier can be used when matching in Perl to ignore case?A sB vC iD c6. Which operator can be used to break up a string into more than one part based upon a separator?A chopB splitC divideD parse7. What option do you use when starting Perl to tell it to run in warning mode? _-w \ use warnings (Fill in the blank.)8. Which control structure can be used to execute only a condition is false?A untilB unlessC whileD without9. Which of the following commands should be used to open a filehandle named KAREN to an existing file named sw?A open KAREN “>sw”;B open KAREN, “>sw”;C open “sw” KAREN;D open “>sw”, KAREN;10. Within Perl, which operator is used to change the working directory?A cdB chdirC pwdD wd11. Which operator can be used to access the first item in an array?A shiftB startC right$D left$12. Within a loop, which operator immediately ends execution of the loop?A nextB lastC redoD leave13. Which function can be used to make sure your program exits with a nonzero status even if there a standard error?A hashB noexitC nozeroD die14. Which of the following operators work most like simple searching/pattern matching?A /fB /gC s///D m//15. Which keyword is used in Perl to define a subroutine?A branchB subC splitD make16. You want to close the directory handle EV AN. Which of the following should you use to accomplish this?A close EV AN;B closedir EV AN;C close_directory EV AN;D none of the above17. Which of the following lines of code accomplishes the same thing as $price = $price + 9;?A $price +9;B $price =+9;C $price +=9;D 9 + $price18. What value do variables have before they are first assigned?A undefB nullC 0D nil19. Which Perl function can be used to launch a child process to run a program?A splitB spinC forkD system20. Which Perl function can be used to identify the first found occurrence of a substring?A findB indexC locateD allocate21. Which control structure can be used to loop as long as a conditional expression returns true?A untilB unlessC whileD without22. Which operator can be used to create private variables within a subroutine?A nativeB limitedC myD regional23. Which of the following operators is used to return a value in a subroutine?A returnB sendC giveD show24. Your script has just read in a variable from the keyboard and you want to strip that variable of the newline character that came in. What operator should you use to perform this operation?A tidyB trimC chompD slim25. What is the default sort order in Perl?A alphabeticB numericC ASCIID none of the above26. Within a loop, which operator jumps to the end of the loop but does not exit the loop?A nextB lastC redoD leave27. (不确定)Which of the following should be used to print values in an array that do not contain newlines and add them to the end of each entry?A print @array;B print @array\n;C print “@array\n”;D print “$@array \\”;28. Which string comparison operator would be equivalent to the numeric > operator?A neB eqC geD gt29. Which function can be thought of as the opposite of split?A linkB joinC uniteD bond30. Which operator can be used to add an item to the bottom of an array?A popB pushC pullD plant31. Which of the following mathematical operations has the highest precedence in Perl?A **B ++C +D -32. 以下哪一个字符串直接量的定义方式是错误的()(1)'thank you'(2)" "(3)"a "friend" of yours"(4)"a \"friend\" of yours"33. 以下哪一条语句是错误的()(1)$_= 'hello world';(2)$a='hello world';(3)my $b,$a='hello world';(4)my ($a,$b)=(0,'hello world');34. 要使下面的程序正常运行,while后的表达式应选()。
汇编语言程序设计(第四版)第4章【课后答案】【精选】

汇编语言程序设计 第四版【课后习题答案】--囮裑為檤第4章 基本汇编语言程序设计〔习题4.1〕例题4.2如果要求算术右移8位,如何修改程序。
〔解答〕思路: 首先由最高位字节向次低位字节传送……次低位字节向最低位字节传送(共7次);再判最高位字节符号位,如为0,送00h 到最高位字节;如为1,送ffh 到最高位字节。
传送可参考例题4.2,不过应从第一号字节送第零号字节,……最高位字节向次低位字节传送;也可以用循环来完成: .model small .stack 256 .dataqvar dq 1234567887654321h .code .startup mov cx,7 mov si,1again: mov al, byte ptr qvar[si] mov byte ptr qvar[si-1],al inc siloop again test al,80h jz ezzmov bl,0ffh jmp done ezz: mov bl,0done: mov byte ptr qvar[7],bl .exit 0 end〔习题4.2〕例题4.2如果要求算术左移7位,如何用移位指令实现。
〔解答〕思路:可设计外循环体为8个字节左移一次,方法是:最低位字节算术左移一次, 次低位字节至最高位字节依次带 CF 位循环左移一次(内循环共8次),外循环体控制执行7次即可。
.model small .stack 256 .dataqvar dq 1234567887654321h4 11 201628.code.startupmov dx, 7 ;外循环次数mov ax, byte ptr qvar[0] ;最低位字节送axlpp: shl ax, 1 ;最低位字节左移一次,其d7移入CF 位 mov si, 1mov cx, 7 ;内循环次数again: rcl byte ptr qvar[si], 1 ;高位字节依次左移 P50 inc siloop again dec dx jnz lpp .exit 0 .end〔习题4.3〕将AX 寄存器中的16位数连续4位分成一组,共4组,然后把这4组数分别放在AL 、BL 、CL 和DL 寄存器中。
汇编语言知识学习程序设计(第四版)第3章【课后答案解析】

汇编语言程序设计第四版【课后习题答案】--囮裑為檤第3章汇编语言程序格式〔习题3.1〕伪指令语句与硬指令语句的本质区别是什么?伪指令有什么主要作用?〔解答〕伪指令语句与硬指令语句的本质区别是能不能产生CPU动作;伪指令的作用是完成对如存储模式、主存变量、子程序、宏及段定义等很多不产生CPU动作的说明,并在程序执行前由汇编程序完成处理。
〔习题3.2〕什么是标识符,汇编程序中标识符怎样组成?〔解答〕为了某种需要,每种程序语言都规定了在程序里如何描述名字,程序语言的名字通常被称为标识符;汇编语言中的标识符一般最多由31个字母、数字及规定的特殊符号(如-,$,?,@)组成,不能以数字开头。
〔习题3.3〕什么是保留字,汇编语言的保留字有哪些类型,并举例说明。
〔解答保留字是在每种语言中规定了有特殊意义和功能的不允许再做其它用处的字符串;汇编语言的保留字主要有硬指令助记、伪指令助记符、运算符、寄存器名以及预定义符号等。
汇编语言对大小写不敏感。
如定义字节数和字符串的DB就是伪指令助记符。
〔习题3.4〕汇编语句有哪两种,每个语句由哪4个部分组成?〔解答〕汇编语句有执行性语句和说明性语句;执行性语句由标号、硬指令助记符、操作数和注释四部分组成;说明性语句由名字、伪指令助记符、参数和注释四部分组成〔习题3.5〕汇编语言程序的开发有哪4个步骤,分别利用什么程序完成、产生什么输出文件。
〔解答〕⒈编辑文本编辑程序汇编语言源程序.asm⒉汇编汇编程序目标模块文件.obj⒊连接连接程序可执行文件.exe或.com⒋调试调试程序应用程序〔习题3.6〕区分下列概念:(1)变量和标号(2)数值表达式和地址表达式(3)符号常量和字符串常量〔解答〕(1)变量是在程序运行过程中,其值可以被改变的量;标号是由用户自定义的标识符,指向存储单元,表示其存储内容的逻辑地址。
(2)数值表达式一般是由运算符连接的各种常数所构成的表达式,地址表达式是由名字、标号以及利用各种的操作符形成的表达式。
Perl语言入门(第四版)习题标准答案

Perl语言入门(第四版)习题答案————————————————————————————————作者:————————————————————————————————日期:《Perl语言入门习题答案》2.12 练习1、写一个程序,计算半径为12.5的圆的周长。
圆周长等于2π(π约为3.1415926)乘以半径。
答案为78.5。
-----------------------/home/confish/perl/girth#!/usr/bin/perl -w#this program calculate a circle's girth#confish@ubuntu7.10$r=12.5;$g=12.5*2*3.1415;print "the girth of the circle is $g\n";-----------------------/home/confish/perl/girth2、修改上述程序,用户可以在程序运行时输入半径。
如果,用户输入12.5,则应得到和上题一样的结果。
-----------------------/home/confish/perl/girthpro#!/usr/bin/perl -w#a better one to calculate girth#confish@ubuntu7.10print"enter the radius of the circle\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is ".$r*2*3.1415."\n";}else{print"nonavailable!\n";}-----------------------/home/confish/perl/girthpro3、修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。
最新Perl语言入门(第四版)习题答案

最新Perl语言入门(第四版)习题答案2.12 练习1、写一个程序,计算半径为12.5的圆的周长。
圆周长等于2π(π约为3.1415926)乘以半径。
答案为78.5。
-----------------------/home/confish/perl/girth#!/usr/bin/perl -w#this program calculate a circle's girth$r=12.5;$g=12.5*2*3.1415;print "the girth of the circle is $g\n";-----------------------/home/confish/perl/girth2、修改上述程序,用户可以在程序运行时输入半径。
如果,用户输入12.5,则应得到和上题一样的结果。
-----------------------/home/confish/perl/girthpro#!/usr/bin/perl -w#a better one to calculate girthprint"enter the radius of the circle\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is ".$r*2*3.1415."\n";}else{print"nonavailable!\n";}-----------------------/home/confish/perl/girthpro3、修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。
-----------------------/home/confish/perl/girthzero#!/usr/bin/perl -w#calculate the girth and print 0 when the radius is lower than 0print"enter the radius of the line\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is $r*2*3.1415\n";}else{print"the girth of the circle is 0\n";}-----------------------/home/confish/perl/girthzero1、2、3:(一起实现的)#!/usr/bin/perl -w$pai=3.4;print "Please Input Radius:";$r=<STDIN>;if ( $r lt 0 ){print "The circumference is 0\n";}else{$l=$r*2*$pai;printf "The circumference is %.1f\n",$l;}4、写一个程序,用户能输入2 个数字(不在同一行)。
Perl语言学习练习及参考答案

#题2:#使用for循环打印出如下的字符。
# 1# 12# 123# 12345#*******************#Fw_Print_Step ($step++,"使用for循环打印出如下的字符。
11212312345");my $str= "";for (1..4) {$str= $str.$_;if ($_==4) {$str= $str.$_+1;}print " $str\n";}#*******************##题3:my $str1 = "abc";my $str2 = "efg";#将上述2个字符串连接起来,并输出合并后的字符串长度#*******************#Fw_Print_Step ($step++,"将上述2个字符串\"$str1\"和\"$str2\"连接起来,并输出合并后的字符串长度");my $str =$str1.$str2;my $str_length=length($str);print "新字串$str的长度为:$str_length";#*******************##题4:#以逆序方式打印出字符串包含的各个字符,如变量为"123456789"则输出为"9","8",..."2","1". my $str1="abc123def456";#*******************#Fw_Print_Step ($step++,"以逆序方式打印出字符串包含的各个字符,如变量为\"123456789\"则输出为\"9\",\"8\",...\"2\",\"1\".");my $str=$str1;print "以逆序方式打印出字符串\"$str1\"包含的各个字符:\n";for($length=length($str1); $length>0; $length--) {$sub_str=chop($str);if ($length>1) {print "\"$sub_str\",";} else {print "\"$sub_str\".";}}#*******************##题5:#分别使用for与while循环来计算1+2+3+...+100的值#*******************#Fw_Print_Step ($step++,"分别使用for与while循环来计算1+2+3+...+100的值"); print "用for循环计算1+2+3+...+100的值:\n ";my $result=0;for (1..100) {$result=$result+$_;}print "1+2+3+...+100=$result";print "\n用while循环计算1+2+3+...+100的值:\n ";my $result=0;my $num=1;while ($num<=100) {$result=$result+$num;$num++;}print "1+2+3+...+100=$result";#*******************##题6:#以逆序的方式打印出端口列表包含的成员口my @cmdArray = ("config", "int fa 0/1", "no shutdonw", "end");#*******************#Fw_Print_Step ($step++,"以逆序的方式打印出端口列表包含的成员口");for (my $start=$#cmdArray; $start>=0; $start--) {my $array=$cmdArray[$start];print "$array\n";}#*******************##题7:#使用foreach打印出Hash表的所有下标与值my %map = ('red', 0xff0000,'green', 0x00ff00,'blue',0x0000ff);#*******************#Fw_Print_Step ($step++,"使用foreach打印出Hash表的所有下标与值");foreach $capword (sort keys(%map)) {print ("$capword: $map{$capword}\n");}#while( ($key, $value) = Each (%Map)) {# Print "\N$key=$value;"}#*******************##题8:#使用正则匹配判断字符串是否包含error,若是打印提示信息。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
最新Perl语言入门(第四版)习题答案2.12 练习1、写一个程序,计算半径为12.5的圆的周长。
圆周长等于2π(π约为3.1415926)乘以半径。
答案为78.5。
-----------------------/home/confish/perl/girth#!/usr/bin/perl -w#this program calculate a circle's girth$r=12.5;$g=12.5*2*3.1415;print "the girth of the circle is $g\n";-----------------------/home/confish/perl/girth2、修改上述程序,用户可以在程序运行时输入半径。
如果,用户输入12.5,则应得到和上题一样的结果。
-----------------------/home/confish/perl/girthpro#!/usr/bin/perl -w#a better one to calculate girthprint"enter the radius of the circle\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is ".$r*2*3.1415."\n";}else{print"nonavailable!\n";}-----------------------/home/confish/perl/girthpro3、修改上述程序,当用户输入小于0 的数字时,程序输出的周长为0,而非负数。
-----------------------/home/confish/perl/girthzero#!/usr/bin/perl -w#calculate the girth and print 0 when the radius is lower than 0print"enter the radius of the line\n";chomp($r=<STDIN>);if($r>0){print"the girth of the circle is $r*2*3.1415\n";}else{print"the girth of the circle is 0\n";}-----------------------/home/confish/perl/girthzero1、2、3:(一起实现的)#!/usr/bin/perl -w$pai=3.4;print "Please Input Radius:";$r=<STDIN>;if ( $r lt 0 ){print "The circumference is 0\n";}else{$l=$r*2*$pai;printf "The circumference is %.1f\n",$l;}4、写一个程序,用户能输入2 个数字(不在同一行)。
输出为这两个数的积。
-----------------------/home/confish/perl/product#!/usr/bin/perl -w#print the two number's product#print"enter the two numbers:\n";chomp($m=<STDIN>);chomp($n=<STDIN>);print"the product of the two numbers are ".$m*$n."\n";-----------------------/home/confish/perl/product5、写一个程序,用户能输入1 个字符串和一个数字(n)(不在同一行)。
输出为,n 行这个字符串,1 次1 行(提示,使用“x”操作符)。
例如,如果用户输入的是“fred”和“3”,则输出为:3 行,每一行均为fred。
如果输入为“fred”和“299792”,则输出为299792 行,每一行均为fred-----------------------/home/confish/perl/printer#!/usr/bin/perl -w#print a string certain times depend on the usr's input#print"enter a string and a number:\n";$str=<STDIN>;chomp($num=<STDIN>);print ${str}x$num;-----------------------/home/confish/perl/printer3.9 练习1、写一个程序,将一些字符串(不同的行)读入一个列表中,逆向输出它。
如果是从键盘输入的,那在Unix 系统中应当使用CTRL+D 表明end-of-file,在Windows 系统中使用CTRL+Z.------------------------------------/home/confish/reprint#!/usr/bin/perl -w#read some input and print them in reverse sequence#print "enter the string please:\n";@str=reverse <STDIN>;print "\nthe reverse strings are:\n@str";------------------------------------/home/confish/reprint2、写一个程序,读入一串数字(一个数字一行),将和这些数字对应的人名(下面列出的)输出来。
(将下面的人名列表写入代码中)。
fred betty barney dino Wilma pebbles bamm-bamm 例如,当输入为1,2,4 和2,则输出的为fred, betty, dino, 和betty------------------------------------/home/confish/num_to_name#!/usr/bin/perl -w#read some numbers and output the match name#$i=0;@names=qw /fred betty barney dino Wilma pebbles bamm-bamm/;print"enter the numbers please:\n";chomp(@nums=<STDIN>);foreach(@nums){@re=@names;while($i ne $_){$n=shift( @re);$i++;}$i=0;print $n,"\n";}------------------------------------/home/confish/num_to_name3、写一个程序,将一些字符串(在不同的行中)读入一个列表中。
然后按ASCII 顺序将它们输出来。
也就是说,当输入的字符串为fred, barney, wilma, betty,则输出为barney betty fred wilma。
分别在一行或不同的行将之输出。
------------------------------------/home/confish/sort_str#!/usr/bin/perl -w#read some strings and sort them in ASCII#chomp(@str=sort<STDIN>);#@str=sort<STDIN>; will print them in diffrent linesprint @str,"\n";------------------------------------/home/confish/sort_str4.11练习1、写一个名为&total 的子程序,返回一列数字的和。
提示:子程序不应当有任何的I/O 操作;它处理调用的参数,返回处理后的值给调用者。
结合下面的程序来练习,它检测此子程序是否正常工作。
第一组数组之和25。
my @fred = qw{ 1 3 5 7 9 };my $fred_total = &total(@fred);print "The total of \@fred is $fred_total.\n";print "Enter some numbers on separate lines: ";my $user_total = &total(<STDIN>);print "The total of those numbers is $user_total.\n";--------------------------------/home/confish/perl/subr#!/usr/bin/perl -w#a subroutine named total returns sum of numbers#sub total{foreach $n(0..$#_){$sum+=$_[$n];}$sum;}my@fred=qw{1 3 5 7 9};my $fred_total=&total(@fred);print"The total of \@fred is $fred_total.\n";print"Enter some numbers on separate lines:\n";my $user_total=&total(<STDIN>);print"The total of those numbers is $user_total.\n";--------------------------------/home/confish/perl/subr2、利用上题的子程序,写一个程序计算从1 到1000 的数字的和。