.BEGIN-ThismarksthestartoftheprogramSUM汇编语言CLEAR-Settherunningsumtoo(line1)INN-InputthefirstnumberN(line2)--ThenextthreeinstructionstestwhetherN isanegativenumber(line3)用汇编语言实现AGAIN:LOADZERO--Puto into registerR如下算法:NCOMPARE-CompareNandoNEGJUMPLT-Go toNEG if N<0对输入的非负整数进行--WegethereifN≥o.WeaddNtotherunningsum(line4)累加,遇到负数停止。SUMLOAD--PutSUMintoRNADDAddN.Rnowholds(N+SUM)OperationSUMSTORE-PuttheresultbadkintoSUMSetthevalueofSumtoo--Getthenext input value(line5)InputthefirstniumberNINNWhileNisnotnegative do--Nowgobackandrepeattheloop(line6)AddthevalueofNtoSumJUMPAGAINInputthenextdatavalueN--WegettothissectionoftheprogramonlywhenweencounteranegativevalueNEG:OUTEndoftheloopSUM-Printthesum(line7)HALTPrintoutSum-andstop(line8)--Here are thedata generation pseudo-opsStopSUM:0.DATA-TherunningsumgoeshereN:0.DATA--The inputdataareplaced here0ZERO:.DATA--Theconstant o--NowwemarktheendoftheentireprogramEND
汇编语言 用汇编语言实现 如下算法: 对输入的非负整数进行 累加,遇到负数停止
问题4:你能说说相比机器语言,汇编语言有些什么好处吗?但是…·
问题4: 你能说说相比机器语言,汇 编语言有些什么好处吗? 但是
我们期望的程序设计语言应该Theprogrammerneednotmanagethedetailsofthemovementofdata itemswithinmemoryorpayanyattentionto exactlywherethoseitemsarestored.Theprogrammercantakeamacroscopicviewoftasks,thinkingatahigherlevel ofproblemsolving (addBand C,and call the resultA).The"primitive operations"used as building blocks in algorithm con-struction (see Chapter 1) can be larger.Programsareportableratherthanmachinespecific.Programmingstatementsareclosertonatural languageandusestan-dardmathematicalnotation
我们期望的程序设计语言应该
问题5:我们要的是“机器为人服务”而不是“人为机器服务”,你觉得我们离这个目标差得远吗?
问题5: 我们要的是“机器为人服务”, 而不是“人为机器服务”,你 觉得我们离这个目标差得远吗?
从算法到程序:一个例子1.Getvaluesfarnandthendataitems数据净化问题:0是无效类aSetthevalueoflegitton024163.Setthevalueof leftto11234Setthevalue of rightton5WhileleftislessthanrightdoSteps6through10问题6:6IftheitematpositionleftisnatOthenincreaseleftby17.Else(theitematpositionleftis0)doSteps8through10你给个算法?8.Reducelegitby19.legit=10Copytheitematpositionrightintopositionleft10.Reducerightby1362324164211.Iftheitematpositionleftiso,thenreducelegitby112.Stoplegit=83616240422327个Theconverging-pointersalgorithmfordatacleanup
从算法到程序:一个例子 数据净化问题:0是无效数据 问题6: 你给个算法?