Help
RSS
API
Feed
Maltego
Contact
Domain > lc3tutor.org
×
More information on this domain is in
AlienVault OTX
Is this malicious?
Yes
No
DNS Resolutions
Date
IP Address
2025-08-14
3.5.81.121
(
ClassC
)
2025-08-18
3.5.80.78
(
ClassC
)
2025-09-08
3.5.80.252
(
ClassC
)
2025-09-22
3.5.86.249
(
ClassC
)
2026-01-11
3.5.81.247
(
ClassC
)
2026-01-18
3.5.77.40
(
ClassC
)
Port 80
HTTP/1.1 200 OKx-amz-id-2: PRtxBgNjxTeB6CEtfvXCzoq3kH3nT9n8kVsZ+jkhAXlo5ekZWAxUI8wnBHhrx7BoJFEgzw3DZLL2UTZT3AIJi/cFfoP7I7xSx-amz-request-id: 72GBS6YA5P7JBE8ZDate: Sun, 18 Jan 2026 01:46:29 GMTLast-Modified: Mon, 27 Aug 2018 03:58:17 GMTETag: 203a273a62952c0e1b886e19bbfe9585Content-Type: text/htmlContent-Length: 177489Server: AmazonS3 !DOCTYPE html>html langen>head> title>LC3 Tutor | Simulator, Help, & Examples for LC3 Assembly Language/title>meta namekeywords contentlc3, lc-3, help, examples, assembler, assembly, tutorial, tutorials />meta namedescription contentSimulator, examples and reference material to help you write, test, and debug your LC-3 assembly programs. />link relapple-touch-icon sizes57x57 href./favicon/apple-icon-57x57.png>link relapple-touch-icon sizes60x60 href./favicon/apple-icon-60x60.png>link relapple-touch-icon sizes72x72 href./favicon/apple-icon-72x72.png>link relapple-touch-icon sizes76x76 href./favicon/apple-icon-76x76.png>link relapple-touch-icon sizes114x114 href./favicon/apple-icon-114x114.png>link relapple-touch-icon sizes120x120 href./favicon/apple-icon-120x120.png>link relapple-touch-icon sizes144x144 href./favicon/apple-icon-144x144.png>link relapple-touch-icon sizes152x152 href./favicon/apple-icon-152x152.png>link relapple-touch-icon sizes180x180 href./favicon/apple-icon-180x180.png>link relicon typeimage/png sizes192x192 href./favicon/android-icon-192x192.png>link relicon typeimage/png sizes32x32 href./favicon/favicon-32x32.png>link relicon typeimage/png sizes96x96 href./favicon/favicon-96x96.png>link relicon typeimage/png sizes16x16 href./favicon/favicon-16x16.png>link relmanifest href./favicon/manifest.json>meta namemsapplication-TileColor content#ffffff>meta namemsapplication-TileImage content./favicon/ms-icon-144x144.png>meta nametheme-color content#ffffff> !link relshortcut icon hreffavicon.ico typeimage/x-icon> link relstylesheet hrefhttps://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css> script srchttps://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js>/script> script srchttps://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js>/script> style> body { /* desktop and ipad */ font-size: 32px; background-color: white; color: black; position: relative; /* for scrollspy */ /*border:3px solid blue;*/ } @media only screen /* iphone 7 only */ and (min-device-width: 300px) and (max-device-width: 600px) { body{ /*border:3px solid red;*/ font-size: 42px; } } /* TOOL TIPS */ /* general */ .bstooltip + .tooltip > .tooltip-inner { background-color: #73AD21; color: #FFFFFF; border: 1px solid green; padding: 15px; font-size: 20px; } /* Tooltip on top */ .bstooltip + .tooltip.top > .tooltip-arrow { border-top: 5px solid green; } /* Tooltip on bottom */ .bstooltip + .tooltip.bottom > .tooltip-arrow { border-bottom: 5px solid blue; } /* Tooltip on left */ .bstooltip + .tooltip.left > .tooltip-arrow { border-left: 5px solid red; } /* Tooltip on right */ .bstooltip + .tooltip.right > .tooltip-arrow { border-right: 5px solid black; }/* HEADER */ .mynavcolors { background-color: white; /* WIP netflix black */ color: black; /* WIP netflix red */ } .mynavbarDIV { background: white; /* WIP netflix black */ opacity: .98; font-size: 120%; display: inline; } .mynavbarDIVsub { margin-top:0rem; }/* BROWSE HEADER */ .mynavSPAN { margin-top: 1rem; margin-right: 4rem; font-size: 65%; opacity: 1.0; display: inline; } .mynavSPAN:hover { font-size: 65%; } /* ABOUT HEADER */ .myAboutSPAN { margin-top:1rem; font-size: 65%; opacity: 1.0; display: inline; float:right; padding-right:3rem; } .myAboutSPAN:hover { font-size: 65%; }/* GLYPH MANAGEMENT */ .myglyphiconSPAN{ color: black; font-size:70%; } .myglyphiconSPAN:hover{ color: #2163AC; /* blue */ } .floatRight { float:right; }/* MAIN SECTIONS */ .container { width:95%; margin-top: 3em; margin-bottom: 0em; background-color: white; color: black; } @media screen and (min-width: 750px) { /* above this is likely desktop, below this is likely phone or tab */ .container { margin-top:0em; } } .sectionAll { padding-top:0em; margin-top:-0em; display:none; /* sections are off until they are explicitly turned on - see updateVisibility() and MAIN */ background-color: white; } .refContent { padding-top:0em; margin-top:-0em; margin-left:3em; margin-right:3em; margin-bottom:5em; display:none; /* sections are off until they are explicitly turned on - see updateVisibility() and MAIN */ background-color: white; } .mynavanchors { background-color: white; color: black; font-size: 120%; font-weight: bold; } .main-title { font-size: 100%; color: black; /* grey fonts */ font-weight:bold; } .simDIV { display:none; margin-top:1em; } .bitscalc { text-align:center; margin-left: auto; margin-right: auto; font-size:65%; padding:.5em; margin-top:.5em; margin-bottom:.5em; background-color:#F2F2F2; max-width:95%; border-radius: .5em; } .bitscalc-sub { margin-left: auto; margin-right: auto; } .noselect { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none; } /* textarea for code */ .textarea-code { width:95%; height:50rem; font-size: 80%; background-color:whitesmoke; padding:1rem; } /*************************//* MODALS *//*************************/ /* Generic Modal used by Samples, Reference modals */ .mymodal { opacity: 0; /*display: none;*/ /* Hidden by default */ pointer-events: none; position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ left: 0; top: .5em; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ margin-bottom: 1em; color: black; /* WIP netflix red */ -o-transition: opacity .4s ease-in-out; -ms-transition: opacity .4s ease-in-out; -moz-transition: opacity .4s ease-in-out; -webkit-transition: opacity .4s ease-in-out; transition: opacity .4s ease-in-out; } /* Modal Content/Box */ .referenceModal-content { background-color: lightsteelblue; /*#878787;*/ margin: 5%; /* 15% from the top and centered */ padding: 1em; border: 1px solid #888; border-color: grey; border-radius: .5em; width: 95%; /* Could be more or less, depending on screen size */ font-size: 100%; max-width: 90%; } .referenceModal-title{ font-weight: bold; font-size: 100%; margin:1rem; color: black; /* WIP netflix red */ } .mymodal-categories { font-size: 75%; max-width: 90%; } .referenceModal-index{ color: black; /* light grey */ font-size: 80%; } .referenceModal-index:hover{ color: #2163AC; /* blue */ } .referenceModal-text{ color: #101000; /* dark grey */ font-size: 80%; } .referenceModal-text:hover{ color: #2163AC; /* blue */ } .asciiModal-content { float:right; background-color: lightSteelblue; /*#878787;*/ margin-top: 5%; margin-right: 2%; /* 15% from the top and centered */ padding: 1em; border: 1px solid #888; border-color: grey; border-radius: 1rem; /*width: 85%; */ /* Could be more or less, depending on screen size */ max-width: 90%; font-size: 100%; } .aboutModal-content { float:right; background-color: lightSteelblue; /*#878787;*/ margin-top: 5%; margin-right: 2%; /* 15% from the top and centered */ padding: 1em; border: 1px solid #888; border-color: grey; border-radius: 1rem; width: 85%; /* Could be more or less, depending on screen size */ max-width: 90%; font-size: 100%; } .aboutModal-title{ font-weight: bold; font-size: 100%; margin:1rem; color: black; /* WIP netflix red */ } .aboutModal-info { font-size: 85%; color: black; /* light grey */ } /* The Modal Close Button */ .myclose { color: #aaa; float: right; font-size: 100%; font-weight: bold; } .myclose:hover, .myclose:focus { color: black; text-decoration: none; cursor: pointer; } /********************//* GENERAL ELEMENTS *//********************/ code { color:blue; font-family: Monaco, monospace; } p{ color:black; } strong { font-weight:normal; color:red; } /style> script typetext/javascript> (function(e,t){var ne.amplitude||{_q:,_iq:{}};var rt.createElement(script);r.typetext/javascript; r.asynctrue;r.srchttps://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-3.4.0-min.gz.js; r.onloadfunction(){e.amplitude.runQueuedFunctions()};var it.getElementsByTagName(script)0; i.parentNode.insertBefore(r,i);function s(e,t){e.prototypetfunction(){this._q.push(t.concat(Array.prototype.slice.call(arguments,0))); return this}}var ofunction(){this._q;return this};var aadd,append,clearAll,prepend,set,setOnce,unset; for(var u0;ua.length;u++){s(o,au)}n.Identifyo;var cfunction(){this._q;return this; };var psetProductId,setQuantity,setPrice,setRevenueType,setEventProperties; for(var l0;lp.length;l++){s(c,pl)}n.Revenuec;var dinit,logEvent,logRevenue,setUserId,setUserProperties,setOptOut,setVersionName,setDomain,setDeviceId,setGlobalUserProperties,identify,clearUserProperties,setGroup,logRevenueV2,regenerateDeviceId,logEventWithTimestamp,logEventWithGroups; function v(e){function t(t){etfunction(){e._q.push(t.concat(Array.prototype.slice.call(arguments,0))); }}for(var n0;nd.length;n++){t(dn)}}v(n);n.getInstancefunction(e){e(!e||e.length0?$default_instance:e).toLowerCase(); if(!n._iq.hasOwnProperty(e)){n._iqe{_q:};v(n._iqe)}return n._iqe};e.amplituden; })(window,document); amplitude.getInstance().init(b06e4a08610fbe8e60d9037d9ef626a9);/script>/head>body classmynavcolors data-spyscroll data-target.navbar data-offset50> nav classnav navbar navbar-inverse navbar-fixed-top mynavbarDIV> div classcontainer-fluid mynavbarDIVsub > span onclickupdateVisibility({wcsimGettingStarted : true}, true) stylefont-size:100%; margin-right:1em> LC3 Tutor/span> span classmynavSPAN onclicktoggleModal({referenceModal: 0}, true);> span titleReference classglyphicon glyphicon-sunglasses myglyphiconSPAN stylefont-size:100%;> /span> /span> span classmynavSPAN onclicktoggleModal({samplesModal: 0}, true);> span titleCode Examples stylefont-size:100%; classglyphicon glyphicon-list myglyphiconSPAN> /span> /span> a classmynavSPAN onclickupdateVisibility({wcsim:true}, true);> span titleLaunch simulator classglyphicon glyphicon-wrench myglyphiconSPAN stylefont-size:100%;> /span> /a> a classmynavSPAN onclickupdateVisibility({QUIZ:true}, true);> span titleOpen Quiz classglyphicon glyphicon-pencil myglyphiconSPAN stylefont-size:100%> /span> /a> a classmynavSPAN onclickupdateVisibility({fptoy:true}, true);> span titleFloating Point Practice classglyphicon glyphicon-pushpin myglyphiconSPAN stylefont-size:100%> /span> /a> a classmynavSPAN onclickupdateVisibility({vnm:true}, true);> span titlevon Neumann Model classglyphicon glyphicon-menu-down myglyphiconSPAN stylefont-size:100%> /span> /a> a classmynavSPAN onclickupdateVisibility({truth:true}, true);> span titleTruth Tables classglyphicon glyphicon-text-size myglyphiconSPAN stylefont-size:100%> /span> /a> span classmyAboutSPAN onclicktoggleModal({aboutModal: 0}, true);> span classglyphicon glyphicon-question-sign myglyphiconSPAN stylefont-size:150%> /span> /span> /div>/nav> div ideverything classcontainer> div idwcsimGettingStarted classrefContent> div classmain-title>LC-3 Simulator: Getting Started/div> p>This page provides quick hints on how to get started with the web-based LC-3 simulator, developed by William Chargin. You can use the same simulator embeded in this site by clicking on simulator icon span titleLaunch simulator classglyphicon glyphicon-wrench myglyphiconSPAN stylefont-size:150%>/span> (at top), or go directly to the original a hrefhttp://wchargin.github.io/lc3web/>here/a> (they are identical).br>br> The Simulator runs in any web browser (requires no loading or installation), and has some great tools to help you get your work done quickly./p> hr> h2>Step 1: Open Editor/h2> p>After jumping to the Simulator page, click ASSEMBLE (at bottom) to open the LC-3 text editor:/p> img src./images/simintro_home_window.jpg altsimulator introduction image> hr> h2>Step 2: Write & Assembly Code/h2> p>After clicking ASSEMBLE on the home page of the simulator, you can type code from scratch, or paste, or drag/drop files ito the editor window. When you are ready, click the Assemble button at the bottom of the editor to see if you program builds properly:/p> img src./images/simintro_assembler_window.jpg altsimulator assembly window> hr> h2>Step 3: Load Simulator:/h2> p>If your code assembled correctly, you are ready to load it into the simulator and return to the simulators main page to run your program/p> img src./images/simintro_assembler_window_load.jpg altsimulator loading image> hr> h2>Step 4: Fix bugs:/h2> p>If errors were detected in your code, review and try assembling again./p> img src./images/simintro_assembler_window_bugs.jpg altsimulator bugs image> hr> h2>Step 5: Run your your code:/h2> img src./images/simintro_assembler_window_controls.jpg altsimulator introduction controls> p>You have various options for running your code. Generally you will want to step or next through each line of your code when you are first getting started./p> ul> li>Step: steps through line by line - including System-level traps like PUTS and OUT, and subroutine calls. Might be too much./li> li>Next: like Step, but skips over function calls including system level traps. This means that subroutines ARE called, and program execution pauses when they return, allowing you to next or step again. Nice for keeping a high-level view of whats going, unless you are chasing a bug in one of your functions or some interaction with a trap or interrupt./li> li>Finish: Finishes execution of the subroutine you are currently in. If you are in the main program, finish will finish your program./li> li>Run: Runs the program from the beginning until a HALT or .END is reached, or termination is forced in some other way. Otherwise, the program will run indefinitely, or until you hit pause/li> li>Pause: Pause execution of the program if it is currently running, preserving the current program counter so that you can step, next, continue, or run again./li> li>Continue: Continue paused execution fromt he current program counter, like run./li> /ul> hr> h2>Step 6: Inspect registers:/h2> img src./images/simintro_assembler_window_register_tooltips.jpg altsimulator inspect registers>br>br> p> Note that you can mouse over any register shown above to see a tool tip that conveys the registers equivalent decimal value.br>br> Registers R0 through R7 will report a signed value decimal equivalent for each register. This means the value interpreted from the twos complement notation will be reported.br>br> Alternatively, the program counter (PC), IR and PSR will be reported as unsigned values, since they represent addresses. /p> /div> !end of getting started> br> /div> !end of ideverything> div idwcsim classsimDIV container> div idbitscalc classbitscalc> span titleBits Calculator stylefont-size:100%; data-toggletooltip data-placementbottom classbstooltip glyphicon glyphicon-calendar myglyphiconSPAN onclicktoggleModal({bitscalcHelpModal: 0}, true);> /span> input idbitscalc-bitscount classbstooltip data-toggletooltip data-placementbottom oninputbitscalcUpdate(c, this.value) typenumber titleSet bit count 1 to 64 value8 namebitscount min1 max64> span idbitscalc-overflow classbstooltip data-toggletooltip data-placementbottom styledisplay:none; titleWarning: overflow occurred on last calculation (per twos complement)> !  /span> input idbitscalc-decimal classbstooltip data-toggletooltip data-placementbottom oninputbitscalcUpdate(#, this.value) typenumber titleEnter decimal value, or arrow up/down value0 stylewidth: 5em namedecimal min-255 max255 > input idbitscalc-hex classbstooltip data-toggletooltip data-placementbottom oninputbitscalcUpdate(x, this.value) typetext titleEnter hex value (like: x111 or x-111), or arrow up/down valuex0 size7 namehex > input idbitscalc-binary classbstooltip data-toggletooltip data-placementbottom oninputbitscalcUpdate(b, this.value) typetext titleEnter a binary value (like: b111 or b-111), or arrow up/down value b00000000 size10 namebinary > input idbitscalc-twoscomp classbstooltip data-toggletooltip data-placementbottom oninputbitscalcUpdate(2, this.value) typetext titleEnter a 2s complement binary value (like: b111 or b011), or arrow up/down value b00000000 size10 nametwoscomp > input idbitscalc-ascii classbstooltip data-toggletooltip data-placementbottom oninputbitscalcUpdate(a, this.value) typetext titleEnter ASCII character, or arrow up/down value size3 namecharacter > span classglyphicon glyphicon-font myglyphiconSPAN bstooltip data-toggletooltip data-placementbottom titledisplay ascii table onclicktoggleModal({asciiModal: 0}, true);>/span> span classglyphicon glyphicon-th myglyphiconSPAN bstooltip data-toggletooltip data-placementbottom titledisplay opcode table onclicktoggleModal({opcodeModal: 0}, true);> /span> span classmyclose bstooltip data-toggletooltip data-placementbottom titleHide Calculator onclickupdateVisibility({bitscalc:false},false)>×/span> br> span> Memory:  input idbitscalc-memory classbstooltip data-toggletooltip data-placementbottom typenumber titleEnter decimal value, or arrow up/down value0 size8 namedecimal min-32768 max32767> span classmyglyphiconSPAN bstooltip noselect data-toggletooltip data-placementbottom titleClear memory onclickdocument.getElementById(bitscalc-memory).value 0> mc /span> span classmyglyphiconSPAN bstooltip noselect data-toggletooltip data-placementbottom titleAdd current value to memory onclickdocument.getElementById(bitscalc-memory).value parseInt(document.getElementById(bitscalc-memory).value) + parseInt(document.getElementById(bitscalc-decimal).value)>m+ /span> span classmyglyphiconSPAN bstooltip noselect data-toggletooltip data-placementbottom titleSubtract current value from memory onclickdocument.getElementById(bitscalc-memory).value parseInt(document.getElementById(bitscalc-memory).value) - parseInt(document.getElementById(bitscalc-decimal).value)>m- /span> span classmyglyphiconSPAN bstooltip noselect data-toggletooltip data-placementbottom titleRecall memory to current value onclickbitscalcUpdate(#, (parseInt(document.getElementById(bitscalc-memory).value)));>mr/span> /span> /div> iframe width1280 height1024 srchttp://wchargin.github.io/lc3web/>/iframe> h5>Credit: https://github.com/wchargin /h5> /div> !quizes> div idQUIZ classsimDIV container> iframe idQUIZChild width1280 height1024 data-srchttp://www.quizjudo.com/set/527109361>/iframe> /div> !float toy> div idfptoy classsimDIV container> iframe idfpToyChild width1280 height1024 data-srchttps://evanw.github.io/float-toy/>/iframe> h5>Credit: https://github.com/evanw /h5> /div>!von Neumann Model> div idvnm classsimDIV container> img idvnmChild stylemax-width:100%; srcimages/jvn_diagram.jpg>/iframe> /div> !Truth Tables> div idtruth classsimDIV container> Enter Circuit Logic Equation:input typetext idtruthChild placeholderlike: and(xor(not(a), 1), or(b, 0)) or like: and(1, 1, 0, 1, 0, 0) onchangedocument.getElementById(truthChildOut).value (eval(this.value.toLowerCase())); this.select() stylewidth:80%; background-color:LightSteelBlue >/input> input typebutton valueHelp onclickalert(NOTE: Truth Tables on this page are rotated so that input values are ROWS instead of traditional COLUMNS (please scroll as needed).\n\n Enter a circuit logic equation as shown above, using any combination of AND, OR, NOT, & XOR. Arguments for gates can be other gates, or 0 (zero) or 1 (one). \n\nYou can also enter arrays of numbers like not(0, 1, 0, 0) for any particular argument to represent that argument from a truth table. Be sure all arrays you enter have the same length! That is, be sure they have the same number of entries. All values should be 0, or 1. Not true. Not false.\n\nWith these equations you can test the output of logic circuits like adders and decoders, or anything you need to build.\n\nLastly, you can define variables including arrays (traditionally columns for your truth table, but we have rotated things here by 90 degrees to make it easier to input strings of numbers) by typing something like a 1, 0, 0, 0, and thereafter you can test XOR(a, a). Have fun.)>/input> br> br> br> Result: br> input typetext placeholderthe result of your equation will show up here idtruthChildOut disabled stylewidth:80%; background-color:DarkSeaGreen >/input> br> br> h3>Available Input (for use in your equation above)/h3> a input typetext idtruthChildA onchangea (eval(this.value.toLowerCase())); this.select(); document.getElementById(truthChildOut).value (eval(document.getElementById(truthChild).value.toLowerCase())); placeholderEnter a value or array of values for like: 1 or like 1, 0, 0, 1 stylewidth:80%; background-color:LemonChiffon >/input>br> b input typetext idtruthChildB onchangeb (eval(this.value.toLowerCase())); this.select(); document.getElementById(truthChildOut).value (eval(document.getElementById(truthChild).value.toLowerCase())); placeholderEnter a value or array of values for like: 1 or like 1, 0, 0, 1 stylewidth:80%; background-color:LemonChiffon >/input>br> c input typetext idtruthChildC onchangec (eval(this.value.toLowerCase())); this.select(); document.getElementById(truthChildOut).value (eval(document.getElementById(truthChild).value.toLowerCase())); placeholderEnter a value or array of values for like: 1 or like 1, 0, 0, 1 stylewidth:80%; background-color:LemonChiffon >/input>br> d input typetext idtruthChildD onchanged (eval(this.value.toLowerCase())); this.select(); document.getElementById(truthChildOut).value (eval(document.getElementById(truthChild).value.toLowerCase())); placeholderEnter a value or array of values for like: 1 or like 1, 0, 0, 1 stylewidth:80%; background-color:LemonChiffon >/input>br> e input typetext idtruthChildE onchangee (eval(this.value.toLowerCase())); this.select(); document.getElementById(truthChildOut).value (eval(document.getElementById(truthChild).value.toLowerCase())); placeholderEnter a value or array of values for like: 1 or like 1, 0, 0, 1 stylewidth:80%; background-color:LemonChiffon >/input>br> f input typetext idtruthChildF onchangef (eval(this.value.toLowerCase())); this.select(); document.getElementById(truthChildOut).value (eval(document.getElementById(truthChild).value.toLowerCase())); placeholderEnter a value or array of values for like: 1 or like 1, 0, 0, 1 stylewidth:80%; background-color:LemonChiffon >/input>br> g input typetext idtruthChildG onchangeg (eval(this.value.toLowerCase())); this.select(); document.getElementById(truthChildOut).value (eval(document.getElementById(truthChild).value.toLowerCase())); placeholderEnter a value or array of values for like: 1 or like 1, 0, 0, 1 stylewidth:80%; background-color:LemonChiffon >/input>br> br> /div> !load> div idLD classrefContent> h1 classmain-title> LD (Load Direct)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({LDI:true},true)>/span> !span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({LDI:true},true)>!/span> span classfloatRight stylefont-size:60%;>Reference/span> /h1> hr> LD R#, addressbr> code>LD R0, LABELbr> LD R0, #102/code>br>br> p>Load a specific register (R0-R7) with the CONTENTS at an address in memory. The address may be represented by a LABEL, where LABEL is defined as follows:br>br> code>LABEL .FILL x1234/code>br>br> In this case, the register will be loaded with the value x1234. This value SITS AT an address (we do not really care which one) that has been tagged with LABEL. LABEL tells LD know where to go to get a value.br>br> Alternatively, an offset value can be specified instead of a label (#102 above). The offset is measured from the location of the LD command.br>br> strong>NOTE: The offset (via LABEL or numeric value) must be a short distance away from LD, since it represents an offset distance to reach forward or backward relative to the LD instruction, (to x1234 in this case). To be specific, the distance from the actual LD command to the LABEL cannot be more than a a signed 9bit value (-256 distance 255)/strong>/p> /div> div idLDI classrefContent> h1 classmain-title> LDI (Load Indirect Addres)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({LDR:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({LD:true},true)>/span> /h1> hr> LDI R#, addressbr> code>LDI R0, LABELbr> LDI R0, #102/code>br>br> p> Get the address that is stored at LABEL (or an offset), and then get the VALUE at THAT address (this is the indirect part).br>br> strong> NOTE: The offset value cannot be bigger than a 9 bit signed value. Specifically -256 distance 255. /strong> br>br> For a good sample on how to use the LDI opcode, please see the a onclickupdateVisibility({stildismp:true},true)>STI/LDI Example/a> in the examples area. /p> /div> div idLDR classrefContent> h1 classmain-title> LDR (Load Relative)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({LEA:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({LDI:true},true)>/span> /h1> hr> LDR R#, R#, addressbr> code>LDR R0, R1, #4/code>br>br> p>Load register R0 with the VALUE AT the address in (R1 + (decimal value 4)). That is, find the address by adding (R1+4), get the value at that address, and put it in R0.br>br> strong>NOTE: The offset value (#4 decimal above) cannot be bigger than a 6bit signed value. Specifically -32 distance 31. So it is an even SHORTER jump than for the LD command which has 9bits available for the offset. /strong> /p> /div> div idLEA classrefContent> h1 classmain-title> LEA (Load Effective Address)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({ST:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({LDR:true},true)>/span> /h1> hr> LEA R#, addressbr> code> LEA R0, LABELbr> LEA R0, #102 /code>br>br> p> Load register R0 with the ADDRESS of LABEL (not its contents!). Often used with .STRINGZ and PUTS to print a string.br>br> Alternatively, an offset value can be specified instead of a label (#102 above).br>br> strong>Note 1: Even if LABEL refers to a string of characters in memory, we are still only loading the ADDRESS of LABEL into R0. Any subsequent PUTS (for example) will get the ADDRESS of the string from R0, and will print characters starting at that address, until a null character is encountered./strong>br>br> strong>Note 2: LABEL must be a short distance away from LEA, since LABEL represents an offset distance to reach forward or backward relative to the LEA instruction, (to x1234 in this case). It is critical that that distance not be too far. To be specific, the distance from the actual LEA command to the LABEL cannot be more than a a signed 9bit value... specifically: -256 distance 255/strong> br>br> For storing and retrieving information from larger distances (outside of the above range), you may want to consider using the LDI and STI opcodes.br>br> See also the STI/LDI Example to see how these opcodes can be used in practice. /p> /div>!store> div idST classrefContent> h1 classmain-title> ST (Store direct)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({STI:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({LEA:true},true)>/span> /h1> hr> ST SR, #####br> code> ST R0, LABELbr> ST R0, #102 /code>br>br> p> Store the VALUE from register SR to the ADDRESS specified by ####.br>br> A LABEL or an offset value can be specified for #### (#102 above).br>br> strong>NOTE: The LABEL or the offset must fit in 9 bits (a short jump). Thats a range of -256 offset 255/strong> /p> /div> div idSTI classrefContent> h1 classmain-title> STI (Store indirect)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({STR:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({ST:true},true)>/span> /h1> hr> STI SR, OFFSETbr> code>STI R0, LABEL/code>br> code>STI R0, #-256/code>br> code>STI R0, #255/code>br> br> p> Store the VALUE from register SR to the ADDRESS specified by the offset ADDRESS.br>br> This is easier than it may sound: STI is simply getting a full address from a nearby LABEL or location that you provide via the limited 9 bit address offset. Then, at that nearby location, it gets the TRUE far away address of where the SR register should be stored. br>br> Heres a simple example:br>br>code>.ORIG x3000br>AND R0, R0, #0; zero out R0br>ADD R0, R0, #11; put a value of 11 in R0br>STI R0, NEARBY; store R0 value at the address in NEARBYbr>; note that NEARBY is a label that must be near (within -256 to 255), but the address it specifies (x4000) can be quite far awayHALTbr>NEARBY .FILL x4000; our near address tells us where to store something far away...br>.ENDbr>/code>br>br> If you check the memory location x4000 after executing this sample, you should see the value x000B (decimal 11) store there.br>br> This opcode is useful especially for larger programs where you cannot reach common memory locations used by many different routines. By picking a safe location in memory at which to store values (like x4000), you can safely store something far away from anywhere in your program as long as you know the address (like x5000). br>br>strong> Note: The address offset cannot exceed the 9 bit range -256 to 255. This is true for the effective offset of any LABEL that is also used. Meaning, if the offset, or the distance to the LABEL from the location of the STI command in memory exceeds the 9 bit range, the assembler will fail, or the code will not access memory properly. When using a LABEL, be sure it is close by. Then, that label can specify the far away address at which to store the source register. /strong> br>br> For a good sample on how to use the STI opcode, please see the a onclickupdateVisibility({stildismp:true},true)>STI/LDI Example/a> in the examples area. /p> /div> div idSTR classrefContent> h1 classmain-title> STR (Store relative)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({ADD:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({STI:true},true)>/span> /h1> hr> STR SR, R#, addressbr> code> STR R0, R1, #4br> /code>br> p>Store the VALUE from register SR to the ADDRESS specified by (R#+OFFSET). So, in the example above, get the value of R1, add decimal 4 to produce and address. THATS where you will store the contents of R0.br>br> strong>NOTE: The offset value (#4 decimal above) cannot be bigger than a 6bit signed value. Specifically -32 distance 31. So it is an even SHORTER jump than for the LD command which has 9bits available for the offset./strong> /p> /div> !math> div idADD classrefContent> h1 classmain-title> ADD (Add)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({AND:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({STR:true},true)>/span> /h1> hr> ADD R#, R#, R#br> code> ADD R2, R1, R0br> ADD R2, R1, #4 /code>br>br> p>Add the values in R1 and R0, and place the result in R2.br>br> Alternatively, you can specify a small incremental value that you want to add to R1, before storing in R2 (#4 above).br>br> strong>NOTE: The offset value (#4 decimal above) cannot be bigger than a 5 BIT signed value. Specifically -16 value 15./strong> /p> /div> div idAND classrefContent> h1 classmain-title> AND (Bitwise AND)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({NOT:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({ADD:true},true)>/span> /h1> hr> AND R#, R#, R#br> code>AND R0, R1, R2/code>br> code>AND R0, R0, #0/code> (a nice trick: sets R0 to zero!)br> br> p>Perform a bitwise and of the individual bits of R1 with R2 and store the final result in R0. br>br> 1 & 1 1;br> 1 & 0 0; br> 0 & 1 0; br> 0 & 0 0;br>br> So that masking the 6th bit from the right using the mask 00100000 is zero:br>br> code>111011101/code> and br> code>000100000/code> br> code>000000000/code>br>br> and masking the 5th bit from the right using the mask b00010000 is not zero (its b10000, which is 2^4 16)br>br> code>11011101/code> and br> code>00010000/code> br> code>00010000/code>br>br> Note that the third argument R3 in code>AND R1, R2, R3/code> acts as a mask that will always indicate if the n-th bit of the R2 was 0 or 1. If the n-th bit was zero, the result is zero, otherwise, the n-th bit must have been a 1.br>br> This technique is often used in conjunction with a branch if zero opcode (BRz) to take a specific action if a particular bit was zero. The converse can also be tested by using the branch if negative or positive command (BRnp) to take action if the result of the AND operation was not zero. br>br> Note that the third argument can alternatively be expressed as a small offset number in decimal (#), hex (x) or binary (b). For example, the following command will mask off only the 2nd bit of R2 and place the result in R1: code>and R1, R2, b00010/code>. The offset notation also provides a quick way to set a registers value to zero, as follows: code>and R1, R1, #0/code>. The prior example works because anding anything with zero will always be zero! br>br> strong>Note: Use caution when expressing offsets via the third argument, as the offset can only utilize a maximum of 5 bits. This means that you can AT MOST increment or decrement a register in the range -16 to +15! /strong> /p> /div> div idNOT classrefContent> h1 classmain-title> NOT (Bitwise NOT)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({BR:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({AND:true},true)>/span> /h1> hr> NOT R#, R#br> code>NOT R0, R1/code>br>br> p>Take the value in R1 as binary number, flip its individual 16 bits (0->1 and 1->0), and store that result in R0/p> /div> !control> div idBR classrefContent> h1 classmain-title> BR (Branch)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({JMP:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({NOT:true},true)>/span> /h1> hr> BR(n|z|p) addressbr> code>BR LABEL/code> (branch always, to the label)br> code>BR #102/code> (branch always, to the offset)br> code>BRn LABEL/code> (branch if negative)br> code>BRz LABEL/code> (branch if zero)br> code>BRp LABEL/code> (branch if positive)br> code>BRzp/code> (branch if > zero)br> code>BRzn/code> (branch if zero)br> code>BRnp LABEL/code> (branch if negative or positive; if not zero)br> code>BRnzp LABEL/code> (branch always)br>br> p>Based on the most recent RESULT of the following opcodes, as stored in ANY register:br>br> code> ADD, AND, NOT, LDI, LDR, LEA /code>br>br> ... branch accordingly. That is, if the result of the recent operation stored in any register was zero, a BRz command will jump to the specified LABEL. If the result was not zero, the BR command will have no effect.br>br> If the result was negative, postive, etc, take the appropriate action, based on the BR(n|z|p) command being used.br>br> For example, if we assume that R1 and R2 are both #-5 and #5, respectively:br>br> code> ADD R0, R1, R2br> BRz LABEL /code>br>br> The above code will jump to the the address specified by LABEL, because the RESULT stored in R0 is zero. (R1 and R2 contents have no effect).br>br> strong>NOTE: LABEL offset must fit in 9 bits (-256 to 255)/strong> /p> /div> div idJMP classrefContent> h1 classmain-title> JMP (Jump register - no return set)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({JSR:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({BR:true},true)>/span> /h1> hr> JMP R#br> code> JMP R0/code>br>br> p>Jump to the address stored in the specified register. br>br> Unlike other jump operations (code>JSR/code> and code>JSRR/code>), a return address is strong>NOT stored in R7 when you use code>JMP/code>./strong>/p> /div> div idJSR classrefContent> h1 classmain-title> JSR (Jump to subroutine via offset- return set)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({JSRR:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({JMP:true},true)>/span> /h1> hr> JSR ########br> code> JSR LABELbr> JSR #102/code>br>br> p>Jump near to LABEL or to the 11bit OFFSET specified. No register is used for the jump to address.br>br> 11 bits provides a maximum range of -1024 to 1023 for the jump.br>br> The jump stores a return address in R7 that can be used to return program flow to the next position after the JSR call.br>br> Either RET or JMP R7 will return to the stored address.br>br> strong> WARNING: TRAPS (OUT, IN, GETC, etc.) that are called AFTER a jump will overwrite R7. Thus, if you are jumping to a subroutine, you must save the contents of R7 immediately to a separate register or memory location when your subroutine starts, to ensure you can return safely to the calling location. /strong> /p> /div> div idJSRR classrefContent> h1 classmain-title> JSRR (Jump to subroutine via Register - return set)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({RET:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({JSR:true},true)>/span> /h1> hr> JSRR R#br> code> JSRR R0/code>br>br> p>Jump to the address stored in R0. No offset can be specified: the jump-to address comes entirely from the specified register. The jump stores a return address in R7 that can be used to return program flow to the next position after the JSRR call.br>br> Either RET or JMP R7 will return to the stored address.br>br> strong> WARNING: TRAPS (OUT, IN, GETC, etc.) that are called AFTER a jump will overwrite R7. Thus, if you are jumping to a subroutine, you must save the contents of R7 immediately to a separate register or memory location when your subroutine starts, to ensure you can return safely to the calling location./strong> /p> /div> div idRET classrefContent> h1 classmain-title> RET (Return via R7 - no arguments))  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({RTI:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({JSRR:true},true)>/span> /h1> hr> code>RET/code>br>br> p>Returns to the address specified in the R7 register, as set by the JSR and JSRR commands.br>br> strong>Note: Traps like OUT, IN, PUTS, etc. will overwrite the R7 value. Thus, if your subroutine uses any Traps, you must store the R7 value immediately at the start of your subroutine to preserve the return address. Thereafter, you can copy it into the R7 register and use the RET command, or you can simply use the following:/strong>/p> code>JMP R7/code> /div> div idRTI classrefContent> h1 classmain-title> RTI (Return from interrupt (no args))  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({GETC:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({RET:true},true)>/span> /h1> hr> code>RTI/code>br>br> p>Returns to the address specified in the R6 register.br>br> This is equivalent to:/p> code>JMP R6/code> /div> !traps> div idGETC classrefContent> h1 classmain-title> GETC (Get character into R0 - no echo)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({OUT:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({RTI:true},true)>/span> /h1> hr> code>GETCbr> TRAP x20/code>  ;same as GETCbr>br> p>Read a character from the console into R0 register (always R0).The character is not echoed which means you will not see your own typing, unless your program prints the character back out (see the OUT trap)br>br>Only one character is read (so GETC is usually inside a loop).br>br>strong>Note: All Traps affect the R7 register, since they are essentially subroutines. If using them from within your own subroutine, be sure you save the contents of the R7 register before you invoke a trap./strong> /p> /div> div idOUT classrefContent> h1 classmain-title> OUT (Print R0 character)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({PUTS:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({GETC:true},true)>/span> /h1> hr> code>OUTbr> TRAP x21/code>  ;same as OUTbr>br> p>Writes the character in the R0 register (bits 0-7) to the console. br>br>Bits 8-15 of Register are ignored (characters only require the lower 8 bits).br>br>strong>Note: All Traps affect the R7 register, since they are essentially subroutines. If using them from within your own subroutine, be sure you save the contents of the R7 register before you invoke a trap./strong> /p> /div> div idPUTS classrefContent> h1 classmain-title> PUTS (Print R0 as string)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({IN:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({OUT:true},true)>/span> /h1> hr> code>PUTSbr> TRAP x22/code>  ;same as PUTSbr>br> p> Write a string of characters to the console from R0 register. Start with the character at the ADDRESS contained in R0. br>br> Only write the first 8 bits from that location (top 8 of the 16 bits are ignored). br>br> Continue at the next memory location until/if it contains the character value 0x0000. (stop at x0000 - dont print it to console).br>br> For example:br>br> code> LEA R0, MESSAGEbr> PUTSbr> MESSAGE .STRINGZ Hi /code> br>br> The above code loads the ADDRESS MESSAGE (a label) into R0.br>br> Then, PUTS prints each letter in memory starting at MESSAGE, until it reaches the end of the string. You should note that the equivalent result will occur with the following code:br>br> code> LEA R0, MESSAGEbr> PUTSbr> MESSAGE .FILL x48; hex for capital Hbr> .FILL x69; hex for lowercase ibr> .FILL x0; hex for end of string (null)br> /code> br>br> This is because the code above lays out memory in the exact way. MESSAGE marks the start of the first letter, and the last letter in sequence is a x0 (interpreted as an end of string by PUTS)br>br> In both examples, R0 simply contains the address of the first letter in a sequence. The only difference is that .STRINGZ is compiler directive that lays out the string in memory for us, so we do not need to convert each character into hex, etc.br>br>strong>Note: All Traps affect the R7 register, since they are essentially subroutines. If using them from within your own subroutine, be sure you save the contents of the R7 register before you invoke a trap./strong> /p> /div> div idIN classrefContent> h1 classmain-title> IN (Get char into R0, with prompt & echo)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({PUTSP:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({PUTS:true},true)>/span> /h1> hr> code>INbr> TRAP x23/code>  ;same as INbr>br> p> Print a generic prompt to the console and read a single character into R0. br>br> The character you type is echoed back to the console for you (you do not need to use OUT to see what you typed)br>br>strong>Note: All Traps affect the R7 register, since they are essentially subroutines. If using them from within your own subroutine, be sure you save the contents of the R7 register before you invoke a trap./strong>/p> /div> div idPUTSP classrefContent> h1 classmain-title> PUTSP (Print R0 as double string)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({HALT:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({IN:true},true)>/span> /h1> hr> code>PUTSPbr> TRAP x24/code>  ;same as PUTSPbr>br> p>PUTSP is a special type of put that writes two characters at a time from from a single memory location. This is possible since registers have 16 bits, and characters only need 8 bits. Thus, memory locations CAN be loaded with two ascii codes - one in the lower 8 bits, and one in the upper 8 bits.br>br>PUTSP starts with two characters at address specified by R0 (The characters themselves are NOT IN R0 - they are at the ADDRESS specified by R0!). br>br>At the address, the first character is based on bits 0-7, and the second character is based on bits 8-15. br>br>Like PUTS, PUTSP stops when 0x0000 is encountered in memory.br>br>strong>Note: All Traps affect the R7 register, since they are essentially subroutines. If using them from within your own subroutine, be sure you save the contents of the R7 register before you invoke a trap./strong> /p> /div> div idHALT classrefContent> h1 classmain-title> HALT (Halt program)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({ORIG:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({PUTSP:true},true)>/span> /h1> hr> code>HALTbr> TRAP x25/code>   ;same as HALTbr>br> p>Stops execution of the program and prints a message to the console.br>br>strong>Note 1: HALT is different than .END (note the dot END). .END is an assembly directive and it simply indicates where the last line of your code exists in memory./strong>br>br>strong>Note 2: All Traps affect the R7 register, since they are essentially subroutines. If using them from within your own subroutine, be sure you save the contents of the R7 register before you invoke a trap./strong> /p> /div> !directives> div idORIG classrefContent> h1 classmain-title> .ORIG (Start of code)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({FILL:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({HALT:true},true)>/span> /h1> hr> code>.ORIG x3000/code>br>br> p> Indicates the starting address where your program should be placed in memory. By convention, the address is usually expressed in hex as x3000, but it can be larger. Valid ranges may depend on the specific LC-3 simulator you are using. When in doubt, use x3000.br>br> Only one .ORIG is allowed per program module. /p> /div> div idFILL classrefContent> h1 classmain-title> .FILL (Fill 16bit memory slot)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({BLKW:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({ORIG:true},true)>/span> /h1> hr> code>.FILL x1234br> LABEL .FILL x1234/code>br>br> p> The .FILL directive fills a 16bit memory location with a single value. The 2nd example above places the hex value 1234 in memory at the location tagged by LABEL.br>br> This value can be anything: an ascii character code, a numeric value, etc, as long as it can fit in 16 bit memory.br>br> Fill values can be specified in hex, binary, or decimal, as indicated below:br>br> code> .FILL x1234 ; hex value 1234 (decimal 4660)br> .FILL #4660; decimal value 4660br> .FILL b1001000110100; binary format (decimal 4660)br> /code>br>br> strong>Note: To avoid confusion, you should always indicate a format (x, b, or #) when specifying numbers/strong> /p> /div> div idBLKW classrefContent> h1 classmain-title> .BLKW (Initialize memory block)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({STRINGZ:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({FILL:true},true)>/span> /h1> hr> code> .BLKW #20br> .BLKW #20 #4br> LABEL .BLKW #20 #4 /code>br>br> p> Initialize successive locations in memory to a value. Note that #, x, or b can be used to indicate the size of the allocation in decimal, hex, or binary. In the above examples, 20 (decimal 20) successive memory locations will be initialized. If no argument is provided after #20 is specified, the initialization value will be zero (#0, or x0000). br>br> A second value can be provided after the #20 to indicate the initialization value for memory. In the above example, all 20 locations will be set to a value of 4.br>br> When used with a label as shown above, the label can be thought of as the start of an ARRAY of data. If each memory location is meant to represent one value that can be represented in 16 bits, then a #20-sized block represents an array of 20 elements, with LABEL indicating the address of the first element in the array.br>br> Note that .BLKW can also be used to effectively initialize a blank string, as might be done with the .STRINGZ directive. /p> /div> div idSTRINGZ classrefContent> h1 classmain-title> .STRINGZ (initilize a string in memory)  span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({END:true},true)>/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({BLKW:true},true)>/span> /h1> hr> code>.STRINGZ Hello World!br> LABEL .STRINGZ Hello World!/code>br>br> p> Declares a group of characters in memory, and terminates that group with a special null character to indicate the end of the string. This means that it takes N+1 memory locations to store your string, where your string has N characters.br>br> Often used with the LABEL directive so that registers can be easily loaded with the address of this string such as:br>br> code> LEA R0, LABELbr> PUTSbr> /code>br>br> In the above case, LEA loads R0 with the ADDRESS of the 1st character of the string (NOT THE STRING ITSELF!). Thereafter, the PUTS directive can be used to print the string referenced by R0, by starting at LABEL and printing each successive character in memory, until PUTS runs into the NULL (x0000) character.br>br> strong>NOTE: You could do the EXACT same thing by using many individual .FILL directives (one for each character) to place each individual characters ascii code (in hex, decimal, or binary notation) into memory. AND by adding an extra Null character to terminate the string. But that would be a lot more typing! Heres what it would look like, roughly:/strong>br>br> code> LABEL .FILL x0048 ; this is hex for capital Hbr> .FILL x0065 ; this is hex for lower case ebr> .FILL x006C; hex for l, etc.br> . ; skipping lo world letters...br> .FILL x0021 ; hex for !br> .FILL x000 ; NULL terminates the string!br> /code> /p> /div> div idEND classrefContent> h1 classmain-title> .END (End of code)  !span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({LDR:true},true)>!/span> span classfloatRight stylefont-size:60%;>Reference/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({STRINGZ:true},true)>/span> /h1> hr> code>.END/code>br> p>Indicates the end of your programs code in memory. Does NOT stop execution of the program (see HALT for that). Should be placed AFTER declaration of any memory storage area you happen to be using via the LABEL, .FILL, .BLKW, or .STRINGZ directives./p> /div> !samples> div idhellosmp classrefContent> h1 classmain-title> Example: Hello World span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({mimicsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> !span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({hellocsmp:true},true)>!/span> /h1> hr> div idhellosmp-react>/div> p> A Simple Hello World program in LC-3 that prints the hello world message one time.br>br> You can copy/paste the code below directly into the LC3 Simulator. Simply click the Assembly button on the main simulator page, paste in the code, click the Assemble button, and then Load into Simulator and run. (Click the help icon for more hints on how to run the simulator) /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(hellosmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idhellosmp-code classtextarea-code>.ORIG x3000 ; code start (note that all comments start after a ;));----------------------------------------; Example: Hello World;----------------------------------------LEA R0, HI ; load the address of the HI labelPUTS ; print hello worldHALTHI .STRINGZ Hello World!\n ; your message.END ; code end /textarea> /div> div idmimicsmp classrefContent> h1 classmain-title> Example: Mimic span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({mimic2smp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({hellosmp:true},true)>/span> /h1> hr> p> A Simple program in LC-3 that asks for a character, and prints it back...forever. Note that a newline character is never echoed back, unless the user types it as input.... how would you fix that? (see Mimic 2). /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(hellosmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idhellosmp-code classtextarea-code>.ORIG x3000 ; code start;----------------------------------------; Example: Mimic;----------------------------------------START ; just a labelINBR START ; jump back to start.END ; code end /textarea> /div> div idmimic2smp classrefContent> h1 classmain-title> Example: Mimic 2 span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({simpleloopsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({mimicsmp:true},true)>/span> /h1> hr> p>A better version of the Mimic sample that asks for a character, and prints it back...followed by a newline character. /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(hellosmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idhellosmp-code classtextarea-code>.ORIG x3000 ; code start;----------------------------------------; Example: Mimic 2;----------------------------------------START ; just a labelIN ; prompt, wait, and echo 1 characterLD R0, NEWLINE ; load the NEWLINE VALUE into R0OUT ; print the value from R0BR START ; jump back to startNEWLINE .FILL x000D ; store the newline character.END ; code end /textarea> /div> div idsimpleloopsmp classrefContent> h1 classmain-title> Example: Simple Loop span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({negatevaluesmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({mimic2smp:true},true)>/span> /h1> hr> p>Implements a simple loop that counts down from 10 (or any number you choose to store). /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(hellosmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy> /span> br> textarea idhellosmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Simple Loop;----------------------------------------LD R1, LOOPMAX; load value at LOOPMAX into R1LD R2, NEG_ONE; load value at NEG_ONE into R2LEA R0, LOOP_MSG; load ADDRESS of LOOP_MSG into R0LOOP_STARTPUTS; print the looping messageADD R1, R2, R1; decrement the R1 loop counter;NOTE: ADD R1, #-1 would also work above!BRp LOOP_START; if R1 is still positive, loop againLOOP_END; else we are done.. this tag really does nothingLEA R0, DONE_MSG; load the address of our done messagePUTS; print the done messageHALTLOOPMAX .FILL x000A ; hex for 10NEG_ONE .FILL #-1 ; decimal for -1LOOP_MSG .STRINGZ Looping...\nDONE_MSG .STRINGZ All Done!\n.END /textarea> /div> div idnegatevaluesmp classrefContent> h1 classmain-title> Example: Negate a value span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({char2valuesmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({simpleloopsmp:true},true)>/span> /h1> hr> p>For two-complement notation, to negate any value you simply invert the bits, and add one (this is 2s complement!).br>br>That process is the same whether converting positive numbers into negative values, or negative numbers into positive values.br>br> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(negatevaluesmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idnegatevaluesmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Negate Value;----------------------------------------LD R0, MY_VALUE; load the value at MY_VALUE into R0NOT R1, R0; invert the bits of R0 and store in R1ADD R2, R1, #1 ; add oneHALT; we are done - R2 should hold positive 123MY_VALUE .FILL #-123.END /textarea> /div> div idchar2valuesmp classrefContent> h1 classmain-title> Example: Convert a character to its representative value span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({string2valuesmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({negatevaluesmp:true},true)>/span> /h1> hr> p>In this sample we want to input a single character, and convert it to its equivalent value: character 0 0, character 1 1, etc. If the input character is 0 quit. Otherwise keeping looping and getting input.br>br>Our strategy: since ascii codes for 0, 1, 2, 3... are sequential, we can subtract the ascii code for 0 from the code for the input character to achieve a value equivalent for the character: ( ascii 1 code - ascii 0 code) 1. /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(char2valuesmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idchar2valuesmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Character to Value;----------------------------------------LOOP_STARTLD R0, NEWLINE; load the VALUE at NEWLINEOUT; print the value in R0 (newline)IN; get ONE character into R0LD R1, ASCII_BASE; load the VALUE at ASCII_BASEADD R0, R0, R1; add the negative base (subtract); now R0 (above) has a VALUEBRnp LOOP_START; jump back to the start if NOT zero (if negative or positive)HALTNEWLINE .FILL x000D ; store the newline characterASCII_BASE .FILL #-48; store the negative ascii code for 0.END /textarea> /div> div idshiftleftsmp classrefContent> h1 classmain-title> Example: Shift Left span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({shiftrightsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({string2valuesmp:true},true)>/span> /h1> hr> p>Shift all bits of register R0 one bit to its left.This is the same as multiplying R0 by 2!(which is the same as adding a value to itself)br>br>Note that if the leftmost bit was already a 1, we will have overflow.That means we lose a bit of information off the left side, because LC-3 registers only have 16 bits to work with. /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(shiftleftsmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idshiftleftsmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Shift Left;----------------------------------------LD R0, ONE; load R0 with the value at label ONEADD R0, R0, R0; double the valueHALTONE .FILL #1; the value of ONE.END /textarea> /div> div idshiftrightsmp classrefContent> h1 classmain-title> Example: Shift Right span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({times10smp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({shiftleftsmp:true},true)>/span> /h1> hr> p>Shift all bits of a number stored in memory by N bits to its right, where N is also specified by a number stored in memory.This is the same as dividing the number by 2 N times!br>br>LC3 does not have a right-shift operation, and our task is further complicated by LC3s lack of a divide operation (we cannot simply divide by 2 N times).br>br>Our strategy will be to essentially reinterpret the stored number from its native binary representation into a new value, by inspecting its individual bits.We will do this by checking each bit of the stored number, and accumulating that bits equivalent value (raised by the appropriate power of 2) into an accumulation register.br>br>If we were not trying to shift the number to the right, this would be a simple matter of just summing up 1 + 2 + 4 + 8 + 16, etc for every bit that is non-zero in the original numbers binary representation.We would just check each bit of the stored number and, if the bit is ONE, then sum up its correspondingpower of two (bit 0 2^0, bit 1 2^1, bit 2 2^2, etc). If the bit was zero, we would not need to sum anything and just move on to the next bit.br>br>Unlike the above simpler case, since we DO want to support a shift right of a number of bits (0-15), this requires thatfor each bit we accumulate into our summation register, we need to add the power of two that corresponds with the shifted bit position (not the position we are testing).In other words, if bit 3 (4 from the right) is set to 1 in our original number, and we want to shift our original number right by 2 bits,then we want to sum up a value of 2^(3-2)2^12 for that 3rd bit (4th from the right). To say it another way, we will reach right by N bits (where is is our SHIFT count)each time we sum up the contribution of a binary bit that is set to ONE.br>br>Certainly this sounds a bit complex, so you may want to review the code below to see one approach to doing that.br>br>We will use bit masks, stored in memory, to help us test whether a particular bit is set, and to help build up our accumulation register.br>br>strong>Note that as we shift right, we are filling in with zeros in the example below. This has the unfortunate side effect of not working correctly for negative number.How would we fix this example to support 2s complement negative numbers? Meaning: if you shift -4 by 1 bit to the right, it should be a -2 (not a positive 2).Ill leave that up to you to figure out!/strong>br>br> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(shiftrightsmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idshiftrightsmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Shift Right;----------------------------------------LD R0, NUMBER_IN; load R0 with the value at NUMBER_IN (the number we want to shift right)LD R1, SHIFT_COUNT; load R1 with the value at SHIFT_COUNT (the number of bits we want to shift right)LEA R2, MASK0; get the base address of the first maskADD R2, R2, R1; test mask: increment the base by the shift count; this is is where we will find the mask we need for the first loop ; R2 now has the test mask that tells us if bit n is set, where n is the SHIFT_COUNT on the first loopLEA R7, MASK0; accumulation mask: get the base address of the first mask; this is what we will add to the accumulator on each loop NOT R1, R1; negate R1, the shift countADD R1, R1, #1;; R1 now has the negative shift count; R6: loop counter: now adjust R6 so that it is the complement of our SHIFT_COUNT by adding 16; R6 16 - SHIFT_COUNTADD R6, R1, #8; add 8ADD R6, R6, #8; add 8: (we wanted to add 16, but had to do it two steps because the offset value for add only supports +15 as a maximum value); if shift count was 1, R1 should now be 15, etc. (remember that we negated R1 above); R6 can now be used as an down counter.. we can subtract 1 on each loop iteration, and when it reaches zero, we are doneAND R3, R3, #0; zero out R3; this will be our accumulator where we will add up values on each loop iterationLOOP_START LDR R5, R2, #0; get the current test mask value and store in R5. AND R4, R0, R5; mask off the current bit to determine if we will add a value to our accumulator; place in R4 BRz CONTINUE; if the R4 was zero, there is nothing to add, so skip over the accumulation step below ; else, that bit was a 1... we need to add the proper mask value to the accumulator (this is the tricky bit) LDR R5, R7, #0; get the accumulation mask based on the R7 register; this will be the current mask divided by 2^SHIFT_COUNT! ADD R3, R3, R5; add R5 to R3 (our accumulator) CONTINUE; prep for next loop iteration ADD R6, R6, #-1; decrement R6, our LOOP counter.. when this reaches zero, we are done (remember it was negative) BRz DONE;if R6 is zero, we are done ADD R2, R2, #1; increment R2, our test mask ADDRESS... for the next loop ADD R7, R7, #1; increment R7, our accumulation mask ADDRESS BR LOOP_START; else loop againDONE ST R3, NUMBER_OUT; store the result HALTNUMBER_IN .FILL b0101010101010101; this is the number we want to shift right, expressed in binary (decimal 21845)NUMBER_OUT .FILL #0; this is our resultSHIFT_COUNT .FILL #4; if we want to shift right by 4 spaces, which is the same as dividing by 2^4 (16)MASK0 .FILL b1; mask off the rightmost (zero) bitMASK1 .FILL b10; mask off the next bit... etc.MASK2 .FILL b100MASK3 .FILL b1000MASK4 .FILL b10000MASK5 .FILL b100000MASK6 .FILL b1000000MASK7 .FILL b10000000MASK8 .FILL b100000000MASK9 .FILL b1000000000MASK10 .FILL b10000000000MASK11 .FILL b100000000000MASK12 .FILL b1000000000000MASK13 .FILL b10000000000000MASK14 .FILL b100000000000000MASK15 .FILL b1000000000000000.END /textarea> /div> div idtimes10smp classrefContent> h1 classmain-title> Example: Times 10 (simple) span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({times10loopingsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({shiftrightsmp:true},true)>/span> /h1> hr> p>Here we will use a brute-force approach to multiply a stored value (in this case #3) by 10. Well place the result in the R2 register when done.br>br>strong>NOTE: our HALT is a trap and will change the values of R0 and R1 at program termination.Be sure to NEXT or step through the program to see the results in those registers before they are overwritten. R2 should remain in tact./strong> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(times10smp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idtimes10smp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Times 10 (simple);----------------------------------------LD R0, VALUE; load the value at VALUE into R0ADD R0, R0, R0; double it (R02x)ADD R1, R0, R0; double again (R1 4x)ADD R1, R1, R1; double again (R1 8x)ADD R2, R1, R0; add 2x (R2 10x); R2 should have #30 which is hex x001EHALTVALUE .FILL #3; decimal 3.END /textarea> /div> div idtimes10loopingsmp classrefContent> h1 classmain-title> Example: Times 10 (looping) span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({functionsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({times10smp:true},true)>/span> /h1> hr> p>Here we will load an initial value into R0, then loop 10 times, adding R0 to an accumulator register R3 each time.The result in R3 will be 10 times R0. Note that the HALT trap will overwrite R0 & R1,so we use R3 to ensure you can inspect the final result after completion. /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(times10loopingsmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idtimes10loopingsmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Times 10 (looping);----------------------------------------LD R0, VALUE ; load the value we want to multipleLD R3, ZERO; stort with zero in R3LD R2, TEN; load the loop maxLOOP_STARTADD R3, R3, R0; add R0 for each loopADD R2, R2, #-1; decrement R2 each loopBRnp LOOP_START; loop back if last operation was not zero (R2); else we are doneHALT; R3 should have our result (R0, R1 will be changed by the trap)VALUE .FILL #3; the value 0TEN .FILL #10; the value 10ZERO .FILL #0; the value zero.END /textarea> /div> div idfunctionsmp classrefContent> h1 classmain-title> Example: Simple Subroutine span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({bitmasksmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({times10loopingsmp:true},true)>/span> /h1> hr> p>Here we will use the JSR opcode to jump to a function via a label, storing the return address in R7. br>br>strong>NOTE: Any traps you use (IN, OUT, PUTS, etc) in your function will overwrite R7, so you need to save R7 somewhere right away in your function, if you plan to use traps./strong>br>br>The sample below loops infinitely, calling the MY_FUNC function label, which gets and writes a single character before returning to main. /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(functionsmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idfunctionsmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Simple Subroutine;----------------------------------------LOOP_STARTJSR MY_FUNC; jump to the MY_FUNC labelBR LOOP_START; repeatMY_FUNCADD R5, R7, #0; copy the return location of R7 into R5, since it will get stomped by IN belowIN; get a characterLD R0, NEWLINE; get the newline character into R0OUT; print newlineADD R7, R5, #0; restore the original R7 valueRET; return from the call, or we could have done a JMP R5!NEWLINE .FILL x000D; this is the newline character.END /textarea> /div> div idbitmasksmp classrefContent> h1 classmain-title> Example: Using a Bit Mask span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({reversestringsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({functionsmp:true},true)>/span> /h1> hr> p>The sample below loads a value from memory and tests if a particular bit of its binary representation is ONE or ZERO. br>br>Our Strategy: use a mask which we know has a specific bit set to one.br>br>ANDing this mask with our value will produce a new value that is only zero if the value did NOT have a 1 in the same bit as our mask.Thus telling us if our values corresponding bit was set or not!br>br>strong>NOTE! We are testing a negative number below: decimal -5. A positive 5 would be represented as b101 (1 four plus 1 one).But since we are dealing in 2s complement for negative numbers, binary for #-5 will be 1111111111111011.So bit 3 will be ZERO. If you change the value to +5, the result will be ONE/strong> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(bitmasksmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idbitmasksmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Using a Bit Mask;----------------------------------------LD R0, VALUE; get the value we want to testLD R1, MASKb3; get the mask for bit 3AND R2, R1, R0; AND the registersBRz IS_ZERO; if the AND was zero, jump to IS_ZERO label; else it must be one...LEA R0, BIT_IS_ONE; load the not set messagePUTS; print itHALT; stop the programIS_ZEROLEA R0, BIT_IS_ZERO; load the is set messagePUTS; print itHALT; stop the programVALUE .FILL #-5; negative 5 in binary is b1111111111111011 (2s complement)MASKb1 .FILL b0000000000000001; a mask for bit 1 (least significant bit)MASKb3 .FILL b0000000000000100; a mask for bit 3MASKb16 .FILL b1000000000000000; a mast for bit 16 (most significant bit)BIT_IS_ONE .STRINGZ \nThat bit is ONE;BIT_IS_ZERO .STRINGZ \nThat bit is ZERO\n;.END /textarea> /div> div idgetlinesmp classrefContent> h1 classmain-title> Example: Get Line span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({initarraysmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({reversestringsmp:true},true)>/span> /h1> hr> p>The sample below loads a line of characters entered by a user and stores them in memory. br>br>Input stops when the user hits the enter key.br>br>The sample below stores each successive character that the user enters into a region of memory that can hold up to 200 characters. br>br>After all text is entered and stored, the program prints out the entire string again from memory to verify that it was properly stored. br>br>We will define enter as the x000A character (ascii for line feed character LF).Note that we could alternatively have used the carriage return character x000D to detect end of user input. br>br>Our Strategy: In a loop, read one character, check for the enter character, and if not enter, then store the character.Otherwise exit. As you may recall, the easiest way to compare an input character to enter is to add the recent inputletter with the NEGATVE of the enter character. If the result is zero, we can branch if zero using the BRz command.Also, we will use the .BLWK assembler directive along with the INPUT_STRING label to reserve 200 consecutive locations in memorythat will be initialized to x0; (null); This special character, when encountered, will stop the PUTS string.br>br> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(getlinesmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idgetlinesmp-code classtextarea-code>.ORIG x3000;---------------------------------------; GET LINE SIMPLE;; register usage:; r0 used initially for the input prompt, and then for capturing each successive input character; r1 negative newline value; r2 accumulator to test for equivalence with newline; r3 our loop counter, used as offset for storing characters; r4 where to store our character in memory;------------------------------------------; pre loop setup LD r1, NEWLINE_NEG; r1 will be our negative newline value AND r3, r3, #0; set R3 to zero... anding any value with zero zero! LEA r4, INPUT_STRING; address where we are storing each new character; will be incremented in the loop; print the input prompt LEA r0, INPUT_PROMPT; load the base address of the prompt string we want to print PUTS; print the string that starts at the r0 address; start getting charactersLOOP_START GETC; get a character (get it into the r0 register always) OUT; echo the contents of the r0 register as a character, back out to the console ADD r2, r0, r1; add negated newline value to the character just input, if they are the same, r2 will be zero BRz EXIT_LOOP; if r20, that is, if the last character was enter then jump out of the loop ; otherwise we want to store the most recent character from r0, and increment the counter ; note: r4 has the address of where we want to store the string STR r0, r4, #0; store the r0 character at the address in r4 PLUS #0 (essentially just store it at r4) ADD r3, r3, #1; increment by one to keep count of the number of letters input so far ADD r4, r4, #1; increment the address of where we want to store the value. BR LOOP_START; loop back againEXIT_LOOP; at this point, we have captured and stored the input string, NOT including the return character LEA R0, RESULT_PROMPT; load the base address of the result prompt into the r0 register PUTS; print out the string that starts from the address at r0, until we run into a string terminator (the x0 value) LEA r0, INPUT_STRING; load the base address of the input string that we have stored PUTS; print the stringHALT; halt execution of the program, if we get this far; this below is our storage area.; for small programs, this is ok - since these labels are within reach of the LD/LEA commands we invoke above; for larger programs, keep in mind that these labels below may be too far away, and a different memory access strategy may be needed. INPUT_PROMPT .stringz \nEnter a line of text:\n RESULT_PROMPT .stringz \nYou entered this text:\n NEWLINE_NEG .FILL x-000A ; store the NEGATIVE value for a newline character INPUT_STRING .blkw #200; allocation enough space to store a character string of 200 individual characters; ; !! note that this allocation above initializes all values of the array to x0, which will be interpretted by PUTS as a the end of a string.END; end of all program commands /textarea> /div> div idinitarraysmp classrefContent> h1 classmain-title> Example: Initialize an Array span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({letterordigitsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({getlinesmp:true},true)>/span> /h1> hr> p>In this sample we will initialize successive memory locations (like an array) to some predetermined value.br>br>It does not really matter how you originally allocated these locations of memory: .FILL or .STRINGZ or .BLKW.As long as the region identified is not filled with active program code, you can overwrite it.(and even if it IS filled with active code, you can overwrite it, but thats for another sample!)br>br>In this sample, we will need to know how many successive memory locations to overwrite.Well predefine some integer value, load it in a register, and just keep filling until weve initilized that many locations.(In a separate example, we will fill memory locations until we hit the special null character: x0.)br>br>In this sample we will overwrite two different types of memory: those allocated by .STRINGZ, and also by .BLKW,just to demonstrate that they are ultimately both just successive memory locations.br>br>strong>NOTE! This fixed memory initialization approach is always a bit dangerous.If you overwrite more spaces than you have allocated ahead of time, you WILL OVERWRITE OTHER MEMORY...and that memory could be your code (like a branch statement), or potentially code that was loaded before yours (prior to x3000, for example, it would be the LC-3 operating system).If/when you do that, very interesting things can happen. If you suspect this has happened to you, just refresh/restart the simulator to ensurethat you have reloaded the LC-3 operating system./strong>/p> span title copy this sample TO the copy buffer onclickdocument.getElementById(initarraysmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idinitarraysmp-code classtextarea-code>.ORIG x3000; start of your code in memory - you always need to start with this;----------------------------------------; Example: Initialize an Array;----------------------------------------; print out the two test strings MY_STRING and MY_BLKW lea r0, BEFORE_PROMPT; load the address! puts; print the prompt lea r0, MY_STRING; load the address! puts; print the string ld r0, NEWLINE; load the newline character (only) study why this is ld, and not lea out; print the character in r0; note we use OUT and not PUTS... because we have only 1 character to print lea r0 MY_BLKW; load the address! puts; print the block ; now we can over-write the stringz and blkw areas with a special character from r1 ; pre-loop setup ld r1, INIT_CHAR; load the charcter we want to use to initialize memory locations ld r2, LOOP_MAX; set r2 to 200; this is our loop counter; well count down to zero lea r3, MY_BLKW; get the address of MY_BLKW into the r3 address... lea r4, MY_STRING; get the address of MY_STRING into the r4 addressINIT_START; start looping str r1, r3, #0; store the character from r1 into the address location stored in r3 (zero offset) str r1, r4, #0; store the character from r1 into the address location stored in r4 (zero offset) add r3, r3, #1; move the r3 pointer forward by 1 memory location - this is the next character we will intialize in MY_BLKW add r4, r4, #1; move the r4 pointer forward by 1 memory location - this is the next character we will init in MY_STRING add r2, r2, #-1; decrement our loop counter by 1; when this gets to zero, we are done! BRnp INIT_START; loop again unless the conditional register is zero based on the r2 addition aboveDONE; DONE looping!; print the strings again: lea r0, AFTER_PROMPT; load the address! puts; print the prompt lea r0, MY_STRING; load the address! puts; print the string ld r0, NEWLINE; load the newline character (only) out; print the character in r0 lea r0 MY_BLKW; load the address! puts; print the block HALT; stop program executionBEFORE_PROMPT .STRINGZ \nHere are the test strings before initialization:\n;AFTER_PROMPT .STRINGZ \nHere are the test strings AFTER initialization:\n;MY_STRING .STRINGZ 01234567890123456789; a string of exactly 20 characters, terminated with a x0 (by the assembler)NEWLINE .FILL x000A; a newline characterMY_BLKW .BLKW #30; a succession of decimal 30 memory locations that are initialized to 0 (blkw always sets to zero).LOOP_MAX .FILL #10; DECIMAL 200!INIT_CHAR .FILL #65; this is the letter A (capital).END/textarea> /div> div idletterordigitsmp classrefContent> h1 classmain-title> Example: Is it a letter or a digit? span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({stildismp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({initarraysmp:true},true)>/span> /h1> hr> p>In this sample, we will look at how to determine if a user-entered character is a letter, or a DIGIT, or anything else.br>br>There are many approaches to doing this, but since ASCII characters A-Z, a-z, and 0-9 are contiguous in the ascii tables(meaning that their ascii codes are grouped together),it is most common to test to see if the input character falls within a specific range of ascii values,between the values of characters at the low and high end of the range for each specific character type.br>br>For a visual representation of the ascii table, you may want to look at a hrefhttp://ascii-table.com/index.php >this/a> page.Keep in mind that ascii values can be expressed in decimal, hex, or binary in LC3 code for most simulators (ex: #3, x3, b11 for decimal 3, hex 3, and binary 3, respectively).Weve chosen decimal in for our .FILL values below... be sure you note the difference when you are writing your code!br>br>We have three separate ranges to test, 0-9, A-Z, and a-z; Our strategy will be to add the input character value to aNEGATED value for A, Z, 0, 1, a, and z, in succession. You can do this in various orders and certainly develop something thatis more optimized than the code below. But hopefully this gives you a sense of the strategy.b>/b>We of course will need to use branch statements based on adding characters together to determine when and where to jump,so we can sort out what type of character has been entered./p> span title copy this sample TO the copy buffer onclickdocument.getElementById(letterordigitsmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idletterordigitsmp-code classtextarea-code>.ORIG x3000;----------------------------------------; Example: Letter or Digit?;----------------------------------------START LEA r0, INPUT_PROMPT; PUTS; GETC; get a character into r0 OUT; echo it back out ; r0 now has the user-entered character we need to test... IS_R0_UPPER; is the character in R0 an upper case letter? ld r1, NEGATIVE_UPR_A_CHR; load A ; is r0 A? add r1, r1, r0; BRn IS_R0_DIGIT; if the add produced a negative number, then r0 is a character below A, so it *could* be a digit; lets go find out... ; else it could still be in A-Z... lets see if it is Z ; is r0 > Z? ld r1, NEGATIVE_UPR_Z_CHR; load Z add r1, r1, r0; BRp IS_R0_LOWER; if the add produced a positive number, then r0 is a character above Z, so it *could* be a lower case letter, but it cannot be A-Z and it cannot be 0-9; lets go find out if it is a-z ; else we know it is between A-Z inclusive, so it must be an upper case letter LEA r0, CONFIRM_UPPER_LETTER; PUTS BR START; repeat IS_R0_LOWER; is the character in R0 a lower case letter? (if we got this far we know it is not A-Z) ld r1, NEGATIVE_LWR_a_CHR; load a ; is r0 a? add r1, r1, r0; BRn IS_R0_DIGIT; if the add produced a negative number, then r0 is a character below a , but above A, so it *CANNOT* be A-Z or a digit, because we would not have gotten this far; must not be a valid character ; else it could still be in a-z... lets see if it is z ; is r0 z? ld r1, NEGATIVE_LWR_z_CHR; load z add r1, r1, r0; BRp IS_R0_OTHER; if the add produced a positive number, then r0 is a character above z, so it cannot be a-z either... must be OTHER ; else we know it is between a-z inclusive, so it must be an lower case letter LEA r0, CONFIRM_LOWER_LETTER; PUTS BR START; repeatIS_R0_DIGIT; if we got this far, it *may be* a digit, but we need to verify ld r1, NEGATIVE_0_CHR; load 0 ; is r0 0? add r1, r1, r0; BRn IS_R0_OTHER; if the add produced a negative number, then r0 is a character below 0 , so it must be other ; else it could still be in 0-9... lets see if it is 9 ; is r0 9? ld r1, NEGATIVE_9_CHR; load 9 add r1, r1, r0; BRp IS_R0_OTHER; if the add produced a positive number, then r0 is a character above 9, so it cannot be 0-9 either... must be OTHER ; else we know it is between 0-9 inclusive, so it must be a number LEA r0, CONFIRM_DIGIT; PUTS BR START; repeatIS_R0_OTHER; if we got this far, it definitely IS NOT a letter or digit LEA r0, CONFIRM_OTHER; PUTS BR START; repeat HALT; never gets here... but just in case!INPUT_PROMPT .STRINGZ \nPlease enter any character:\nCONFIRM_UPPER_LETTER .STRINGZ \nThat is an upper case letter!\n;CONFIRM_LOWER_LETTER .STRINGZ \nThat is a lower case letter!\n;CONFIRM_DIGIT .STRINGZ \nThat is a numeric digit!\n;CONFIRM_OTHER .STRINGZ \nThat is not a letter or a digit\n;NEGATIVE_UPR_A_CHR .FILL #-65; char A ascii code, negatedNEGATIVE_UPR_Z_CHR .FILL #-90; char Z ascii code, negatedNEGATIVE_LWR_a_CHR .FILL #-97; char a ascii code, negatedNEGATIVE_LWR_z_CHR .FILL #-122; char z ascii code, negatedNEGATIVE_0_CHR .FILL #-48; char 0 ascii code, negatedNEGATIVE_9_CHR .FILL #-57; char 9 ascii code, negated.END /textarea> /div> div idstildismp classrefContent> h1 classmain-title> Example: STI/LDI (store-to & load-from far away) span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({demorganorsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({letterordigitsmp:true},true)>/span> /h1> hr> p> This example demonstrates the simplest use of the code>STI/code> and code>LDI/code> opcodes. Here we will use a near-by label (in this case NEARBY) to get the address of a far-away memory location. That far away location (in this case xFFFF, which is the largest addressible location... do you know why?) is where code>STI/code> stores the value from the specified register. After storing a value at that location, we will zero out the register and retrieve the value using the LDI opcodebr>br> This technique is especially useful when working in larger programs and with common areas of memory (like an array or matrix) that must be accessed from various subroutines. Because the opcodes code>ST/LD/code>(9 bits) and code>STR/LDR/code> (6 bits) only support limited offset addressing, they can only be used to access nearby locations when storing. code>STI & LDI/code> solve that problem by using an indirection to get at a full 16 bit address.br>br> In the example below, the decimal value #11 (hex x000b) is initially placed in R0. Then, R0s VALUE is stored via STI at the xFFFF memory location. R0 is then zeroed out, and the same value is retrieved using the LDI opcode. After executing this program in the simulator, you should see hex x000B in the R0 register, and you should be able to check the xFFFF memory location by typing xFFFF into the Jump to address field of the simulator. Doing so should show you a list of memory locations directly below, ending with xFFFF. The value you find in the xFFFF location should be x000B (decimal #11). /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(stildismp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idstildismp-code classtextarea-code>.ORIG x3000;---------------------------------------------------------; Example: STI / LDI (store-to and load-from far away);---------------------------------------------------------AND R0, R0, #0; zero out R0ADD R0, R0, #11; put a value of 11 in R0STI R0, NEARBY; store R0 value at the address in NEARBYAND R0, R0, #0; zero out R0 againLDI R0, NEARBY; get the value backGETC; force pause for input so you can inspect registersHALTNEARBY .FILL xFFFF; our near address tells us where to store something far away...; in this case (above) our far away address is xFFFF, but it could be anywhere that does NOT contain executable code.; that is - we would not want to store something on top of an opcode you have written!; it is worth noting that the far-away address can be beyond the address of the .END directive; (you do not need to explicitly allocate a memory block ahead of time in order to store something in it using the STI opcode..END /textarea> br>br> p> To anchor your understanding of STI, you may want to consider that the above example could also have been accomplished with the code below. In this alternate example, we simply use the LD opcode to load an address into a spare register R3, and then we use code>STR SR, R#, #0/code> to store the source register SR into the address represented by (R#+#0). This works because STR adds zero to R#, and effectively we are just doing code>STX SR, DR/code> (though STX does not exist).br>br> strong> Question: Why not just have an code>STX SR, DR/code> command?br> Answer: Because code>STR SR, R#, #offset/code> is actually more useful. It allows us to store values into locations that are offset from the DR base address (albeit with a limited precision of 6 bits or -32 to 31) /strong> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(stildismp-code2).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idstildismp-code2 classtextarea-code>.ORIG x3000;----------------------------------------; Example: STR / LD (alternative to STI/LDI);----------------------------------------AND R0, R0, #0; zero out R0ADD R0, R0, #11; put a value of 11 in R0LD R1, NEARBY; load the address stored at NEARBYSTR R0, R1, #0; store R0 value at the address in NEARBY, offset by zeroHALTNEARBY .FILL xFFFF; our near address tells us where to store .END /textarea> /div> div iddemorganorsmp classrefContent> h1 classmain-title> Example: De Morgans OR (OR two registers) span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({restoreregisterssmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({stildismp:true},true)>/span> /h1> hr> p> In this example, well demonstrate De Morgans law for implementing a bitwise OR function, by using only code>AND/code> and code>NOT/code>.br>br> The formula we will use is: code> (X OR Y) NOT( NOT(X) AND NOT(Y) ) /code>br>br> So we need to compute the complement (NOT) of two registers, and then and those registers, and finally NOT the result of that AND.br>br> To help illustrate what is going on, well use binary literals for our code>ADD/code> calls, to load Registers R1 and R2 with complementary values. Then, well store the result at a location in memory (via THE_ANSWER label) so you can inspect it after program execution. /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(demorganorsmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea iddemorganorsmp-code classtextarea-code>.ORIG x3000;-------------------------; OR TWO Registers;; USE: De MorganÕs rule: X OR Y NOT(NOT(X) AND NOT(Y));----------------------------AND R1, R1, #0; zere out R1AND R2, R2, #0; zero out R2ADD R1, R1, b1010; set R1 to this binary valueADD R2, R2, b0101; set R2 to this binary value - which is conveniently the complement of R1; proper ORing of R1 and R2 should produce decimal #15 (hex x000F),NOT R1 , R1 ; assign R1 NOT(R1)NOT R2 , R2 ; assign R2 NOT(R2)AND R3 , R1 , R2 ; R3 NOT(R1) AND NOT(R2)NOT R3 , R3 ; R3 NOT(R3) which is: (R1 OR R2)LEA R4, THE_ANSWER; get the address of THE_ANSWER STR R3, R4, #0; store R3 at the address in R4 (with #0 offset); now the answer can be found in memory at the location of THE_ANSWER; the value should be x000F (decimal 15)HALTTHE_ANSWER .FILL x0; well store our answer here.END /textarea> /div> div idrestoreregisterssmp classrefContent> h1 classmain-title> Example: Storing and Re-storing Registers (in subroutines) span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({array2Dcolordersmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({demorganorsmp:true},true)>/span> /h1> hr> p> In this example, well illustrate a somewhat tricky way to store and restore registers in all of your subroutines.br>br> When writing larger programs, you will no doubt run into situations where you need to store register values right away when you start out in a subroutine. This is especially critical for the R7 register, which is set by the code>JSR/code> and code>JSRR/code> calls so that you can use code>RET/code> at the end of your subroutine. (R7 tells code>RET/code> where to go back to!). br>br>If you have changed the R7 register in anyway during your subroutine, and you have not saved it somehow, you can not get back to the calling routine. Even if you do not change R7 directly, you may use a TRAP like PUTC or GETC, etc while in your subroutine. These traps CHANGE registers like R7 and potentially R0. So, backing up registers is really a good habit to get into.br>br> Here is one approach to do that...br>br> Our strategy attempts to minimize the use of labels for registers in each of your subroutines. A typical approach would be to create a label for every register in every subroutine and store to/load from those labels for each register. Thats (8 registers) x (M subroutines)... if you have 10 subroutines, thats 80 labels!br>br> In our approach, well put a .blkw statement to allocate 8 memory locations immediately before the label of each subroutine. We KNOW where the register memory locations are for each subroutine. They are at SUBR_NAME-1, SUBR_NAME-2, SUBR_NAME-3, etc. So, since we know where they are, we can store to them fairly easily, just by referencing the name of the subroutine we are in!br>br> The key is that for each successive line of code that ST stores into a location in memory, we have to reach back twice as far to reach the next available location. br>br> Take a look at the sample code below. Once you understand it, you should have an even more solid grasp on addressing memory with LC-3.br>br> strong>Note that the register storing and loading code for each subroutine A, B, & C (below) are virtually identical, other than the name of the subroutine itself. No messy labels! /strong> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(restoreregisterssmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idrestoreregisterssmp-code classtextarea-code>.ORIG x3000;------------------------------------------; Example: Storing and Restoring Registers;; In this sample we present a strategy for storing and recovering registers in every subroutine.; This approach allows subroutines to call other subroutines, since every subroutine backs up registers in its own private area; This approach also minimizes potential naming errors, since the code for each subroutine is almost identical.; Unlike other approaches, you do not need to keep a unique label storing every register in every subroutine.; Because we use the name of the subroutine itself to find our register storage area in each subroutine, we avoid using a large number of labels.; It is critical however that the .blkw statement we use to allocate space for our register storage be placed exactly before the subroutine name.; You can create other local subroutine variables above the register block, just be sure the register block (.blkw) is immediately before; the subroutine label. Note also that in many cases, you may want to return a register value with changes (like returning a value from a function).; That is, the job of your subroutine may be to actually return a value in R0, R1, etc. In these cases, be sure to comment out the; restore register code for the registers you have changed and with to return to the calling function.;; Note that the storing and loading code for each subroutine are virtually identical, other than the name of the subroutine itself. No messy labels!;--------------------------------------------AND R0, R0, #0; zero out all registersAND R1, R0, #0;AND R2, R0, #0;AND R3, R0, #0;AND R4, R0, #0;AND R5, R0, #0;AND R6, R0, #0;AND R7, R0, #0;ADD R0, R0, #0; initialize all registers with a value (this coulbe anything*)ADD R1, R0, #1; ADD R2, R0, #2; ADD R3, R0, #3; ADD R4, R0, #4; ADD R5, R0, #5; ADD R6, R0, #6; ADD R7, R0, #7;JSR SUBR_A; Jump to SUBR A (which will jump to B, and B will jump to C, before returning in chain fashion)LEA R0, PRINT_DONE; load this address of PRINT_DONE;PUTS; print DONE!GETC; this will simply pause program execution so you can inspect register R0-R7; you should see that registers have the same values 0,1,2,3-7 at this point, as when they started.HALTPRINT_DONE .STRINGZ \nDONE!\n;;------------------------; SUBR A;------------------------PRINT_SUBR_A .STRINGZ Here in SUBR_A!\n.blkw #8; register back up zone: room for 8 registersSUBR_A ; store all registers, note we have to reach back twice as far on each line to reach the next available memory location ST R0, #-2; store R0 at mem-2 from here (in the .blkw section) ST R1, #-4; store R1 at mem-4 from here ST R2, #-6; etc. ST R3, #-8; ST R4, #-10; ST R5, #-12; ST R6, #-14; ST R7, #-16; ; do work here! ADD R0, R0, R0; double register values.. just to make a change ADD R1, R1, R1; ADD R2, R2, R2; ADD R3, R3, R3; ADD R4, R4, R4; ADD R5, R5, R5; ADD R6, R6, R6; ADD R7, R7, R7; LEA R0, PRINT_SUBR_A; prove we made it ok PUTS; JSR SUBR_B; CALL B FROM HERE ; restore all registers LEA R7, SUBR_A; load the address of this subroutine LDR R0, R7, #-1; recover all registers, in this order! LDR R1, R7, #-2; LDR R2, R7, #-3; LDR R3, R7, #-4; LDR R4, R7, #-5; LDR R5, R7, #-6; LDR R6, R7, #-7; LDR R7, R7, #-8; R7 has to be last, since we overwrite the R7 address offset RET ;------------------------; SUBR B;------------------------PRINT_SUBR_B .STRINGZ Here in SUBR_B!\n.blkw #8SUBR_B ST R0, #-2; store R0 at mem-2 from here (in the .blkw section) ST R1, #-4; store R0 at mem-4 from here ST R2, #-6; etc. ST R3, #-8; ST R4, #-10; ST R5, #-12; ST R6, #-14; ST R7, #-16; ; do work here! ADD R0, R0, R0; double register values.. just to make a change ADD R1, R1, R1; ADD R2, R2, R2; ADD R3, R3, R3; ADD R4, R4, R4; ADD R5, R5, R5; ADD R6, R6, R6; ADD R7, R7, R7; LEA R0, PRINT_SUBR_B; prove we made it ok PUTS; JSR SUBR_C; Call C from here... ; restore all registers LEA R7, SUBR_B; load the address of this subroutine LDR R0, R7, #-1; recover all registers, in this order! LDR R1, R7, #-2; LDR R2, R7, #-3; LDR R3, R7, #-4; LDR R4, R7, #-5; LDR R5, R7, #-6; LDR R6, R7, #-7; LDR R7, R7, #-8; RET;------------------------; SUBR C;------------------------PRINT_SUBR_C .STRINGZ Here in SUBR_C!\n.blkw #8SUBR_C ST R0, #-2; store R0 at mem-2 from here (in the .blkw section) ST R1, #-4; store R0 at mem-4 from here ST R2, #-6; etc. ST R3, #-8; ST R4, #-10; ST R5, #-12; ST R6, #-14; ST R7, #-16; ;do work here! ADD R0, R0, R0; double register values.. just to make a change ADD R1, R1, R1; ADD R2, R2, R2; ADD R3, R3, R3; ADD R4, R4, R4; ADD R5, R5, R5; ADD R6, R6, R6; ADD R7, R7, R7; LEA R0, PRINT_SUBR_C; prove we made it ok PUTS; ; restore all registers LEA R7, SUBR_C; load the address of this subroutine LDR R0, R7, #-1; recover all registers, in this order! LDR R1, R7, #-2; LDR R2, R7, #-3; LDR R3, R7, #-4; LDR R4, R7, #-5; LDR R5, R7, #-6; LDR R6, R7, #-7; LDR R7, R7, #-8; RET .END /textarea> /div> div idstring2valuesmp classrefContent> h1 classmain-title> Example: Convert a string to its representative numeric value span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({shiftleftsmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({char2valuesmp:true},true)>/span> /h1> hr> p>In this sample we want to convert a string of characters that is already stored in memory (via a .STRINGZ directive), into its equivalent numeric value, and store that value in a register.br>br>We will assume that the string represents a positive or negative decimal value which can be stored a 16 bit register without overflow.(Note that dealing with overflow - detecting and warning the user - requires additional work beyond the scope of this example)br>br>We will allow our string of numeric characters to be optionally prefixed with a dash character (-) to indicate if it is a negative value.br>br>We will also do some basic checking to ensure that the string does not contain any bad characters. Only 0-9 and - should be allowed.br>br>We will store the resulting value in the R3 register when completed, so it can be inspected after completion of the program.Remember that you can mouse over a register value in the simulator to see a tooltip of its equivalent decimal value.Thats a quick way to confirm that the final decimal value matches the original decimal string.br>br>Our Strategy: The key to conversion is to convert each ascii digit character in succession to its numeric value (2 become 2, etc)and store that value in an accummulation register (R3). Thereafter, on each new loop iteration, we will multiple that R3 register by 10,before we add in the next digits value. The x10 step gives all prior digits their proper value, as we proces each new digit in the string.br>br> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(string2valuesmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idstring2valuesmp-code classtextarea-code>.ORIG x3000;--------------------------------------------------------------; Example: CONVERT A STRING TO A NUMBER;; Convert a single string of characters that is ALREADY stored in; memory to their equivalent integer value. Process only integers,; including the - sign like: 12345 or -45677.;; Abort and return no value if an illegal character is encountered; (any character other than -, 0-9);; Register usage:;; R0 current character being worked on; R1 negative of the dash character, and later negative of the zero; character 0, lastly our sign value at the end; R2 base address of our number string; will be incremented on each loop cycle; R3 accumulation register... where we will add up the value of each; successive digit with 10X of the prior loops accumulation; R4 work register;-----------------------------------------------------------------JSR START; jump over this local storage area directly below to the START LABEL ; we define this area below to keep some information nearby so we can safely use the LEA and ST opcodes... ; because these opcodes have a limited reach of -256 to 255 range for their label or offset value ; for larger programs we would likely use the STI & LDI opcodes to store and load from far away START_MSG .STRINGZ \nConverting the following string to a number:\n; this is our starting prompt NEG_ZERO .FILL #-48; ascii decimal -48 negative of character 0 (zero)... we can add this to any number character to see what its value is ; note that if the sum after adding -48 is LESS than Zero or GREATER than 9, we know the original character was invalid and we should abort ; NEG_DASH .FILL #-45; ascii decimal -45 negative of character - (dash)... we will add this to the first character of the string to see if it is negative DASH_FOUND .FILL x0; a boolean flag... x0 if we do NOT find a dash as the first character character, else 1 ; note above that the assembler will convert this .STRINGZ directive into the equivalent of two .FILL statements: the first a space , and the second a NULL #0 to terminate the string ; if we encounter a dash character in the input string, we will store it here in the first position ; if not we will leave this string unchanged ; at the end we will simply print this character using PUTS before we print the final number NUMBER_STRING .STRINGZ 1234; string of character we want to convert to a number; ; !! note that the .STRINGZ directive above automatically converts our string into successive memory locations, ; each with the ascii code for a single character stored in memory, thereafter terminating the string with a x0, ; which will be interpreted by PUTS as a the end of a stringSTART; this is where we really start our program (after the memory declarations above) LEA R0, START_MSG; get the address of the start message PUTS; print the message LEA R0, NUMBER_STRING; get the address of the start of the number string PUTS; print the string LEA R2, NUMBER_STRING; load the base address of our stored number string into the R2 register LDR R0, R2, #0; get the character at the R2 location into R0 BRz LOOP_END; if the character we just got was x0 (nul - the string terminator), then we are done (null string check) ; else... we need to check for a - sign character LD R1, NEG_DASH; load the negative of the dash character in R1 ADD R1, R1, R0; add R1 to R0 and store in R1, to see if it was a dash - zero means a dash! BRnp POSITIVE_NUMBER; if the result is not zero, then we know the character was not a dash and so it is a positive number ; else it must be a dash - so our number will be negative... NEGATIVE_NUMBER ; dash: set a flag and get another character AND R3, R3, #0; initialize R3 to zero ADD R3, R3, #1; add one to create our true value of 1, that we will stored in DASH_FOUND; ST R3, DASH_FOUND; store the value at the DASH_FOUND label (NOTE: short jump... DASH_FOUND cannot be more than 255 away!) ; skip over the dash & get the next character ADD R2, R2, #1; increment the address counter to get the next character we want to process LDR R0, R2, #0; get the character at the R2 location into R0 POSITIVE_NUMBER ; no dash: do nothing LD R1, NEG_ZERO; load negative of the zero character in R1 so we can determine if each successive character is number or not ; Note: we will use R1 on each loop iteration without changing its value AND R3, R3, #0; zero out R3 - this will be our accumulator for the converted value of our string ; we will multiply R3 by 10x on each loop iteration LOOP_START; now we are ready to process the R0 value, and loop til the end of string ; R0 has the character we are going to convert to a value ADD R0, R0, R1; subtract the zero characters ascii value from it to get a real value. BRn BAD_CHARACTER; if the result in R0 is negative, then the character we got must have been bad ; ( that is, less than 0 in the ascii table) ADD R0, R0, #-9; subtract 9... if the result is positive, then the character must have been bad because it was bigger than 9 BRp BAD_CHARACTER; ADD R0, R0, #9; else add back the 9 to R0 (so we only have values from 0 to 9), ADD R3, R3, R0; and add R0 (the value of our new character) to the current contents of the R3 register ADD R2, R2, #1; increment the address counter to get the next character we want to process LDR R0, R2, #0; get the character at the next location into R0 BRz LOOP_END; if the character we just got was x0 (zero), then we are done ; else... ; multiply what ever is in R3 by 10... we will do this each time we come through the loop ; to ensure that the accumulated result (if any so far) is shifted to the left 1 position in base 10 ADD R3, R3, R3; double it (R32x) ADD R4, R3, R3; double again (R4 4x) ADD R4, R4, R4; double again (R4 8x) ADD R3, R4, R3; add 2x (R3 10x) ; R3 should be x10; R4 has been modified, but can be used for something else now BR LOOP_START; loop back LOOP_END ; at this point, R3 should have the numeric value of our string.... ; we need to negate the value in R3 if a dash was encountered as the first character LD R1, DASH_FOUND; get the flag - zero or one ADD R1, R1, #0; do an ADD operation, to force our condition code bits to be set BRz ALL_DONE; the number is positive, so no need to negate.. jump to done ; else we need to negate R3... DO_NEGATE NOT R3, R3; invert the bits of R0 and store in R1 ADD R3, R3, #1 ; add one ALL_DONE; R3 now has the value equivalent if our initial string at NUMBER_STRING, unless there was a bad character ; print final message LEA R0, DONE_MSG PUTS; print the message HALT; BAD_CHARACTER LEA R0, ABORT_MSG; PUTS; LDR R0, R2, #0; get the character at the current R2 location into R0 OUT; print the character HALTHALT; halt execution of the program, if we get this far; this below is our storage area.; for small programs, this is ok - since these labels are within reach of the LD/LEA commands we invoke above; for larger programs, keep in mind that these labels below may be too far away, and a different memory access strategy may be needed.DONE_MSG .STRINGZ \nAll done please check the value of the R3 register.ABORT_MSG .STRINGZ \nI am sorry - that input number has an invalid character. \nOnly 0-9 or the - character are allowed. \nThe invalid character was: .END; end of all program commands /textarea> /div> div idreversestringsmp classrefContent> h1 classmain-title> Example: Reverse the characters in an in-memory string span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({getlinesmp:true},true)>/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({bitmasksmp:true},true)>/span> /h1> hr> p> In this example, we will reverse the characters of a string which has already been stored in memory. br>br> Our string must be terminated using the null character (#0), as is done automatically when the string is created using the .STRINGZ assembler directive. br>br> Our strategy will be to set up tracking pointers (registers with address values in them) that point to the first and last character of the string. Then, we will progressively swap the characters at those locations, and move the pointers one location closer to each other in memory, until they meet in the middle. br>br> The only tricky part is ensuring that the pointers do not cross over each other and continue off into infinity and beyond (causing a compiler halt). To avoid that, we just need to be sure our branch conditions are set up properly based on the address-math that we do in our program. br>br> strong>NOTE: Since we will be doing address math on 16 bit register addresses, there is a definite case where our code can fail due to overflow conditions. Namely, if the location of the string in memory exceeds the precision of a 15bit number, our negation step to create a negative address will fail. br>br> Can you think of a way to solve this problem?/strong> br>br> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(reversestringsmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idreversestringsmp-code classtextarea-code>.ORIG x3000;----------------------------------------------------------; Example: Reverse the characters of an in-memory string;; REGISTER USAGE:; R0 address of start of string, which will be incremented as we swap; R1 address of end of string, which will be decremented as we swap; R2 temp character holder; R3 temp character holder; R4 address math: R0 - R1 (when will this step result in overflow??!);------------------------------------------------------------; pre-loop set up LEA R0, MY_STRING; get the address of the first charcter in the string ADD R1, R0, #0; set R1 to be equal to R0 (start of string); Now we will increment R1 gradually until we find the null character that terminates the string...; (.STRINGZ will always use a null character to indicate the end of a string); Note that since the NULL character has a value of zero we can simply use a BRz check to; branch if/when the null character is loaded; FIND THE ADDRESS OF THE LAST CHARACTER LOOP_START; LDR R2, R1, #1; sets the CCR based on the value we store in R2 from the address (R1 + 1) BRz LOOP_END; if the character we grabbed in R2 was null (zero), then R1 is at the the last character of the string ; above: note that the #1 offset we used on the LDR statement reached one memory position farther than R1 in the string to check for the null character ; so R1 is actually the address of the last character, NOT the address of the null character. ; Be sure you understand this difference! ; else if we did not jump, then the R1 address is not at the last character yet ADD R1, R1, #1; add one to the R1 pointer to move to the next character in the string BR LOOP_START; and loop around again (unconditional branch) LOOP_END; jump here from above if we detected a null character at address (R1+1). ; at this point R1 should be pointing to our last character... ; and R0 is still the first characters address ; we are ready to begin our character swapping; START SWAPPINGSWAP_START LDR R2, R0, #0; copy the character from the front of the string to the the temp R2 register LDR R3, R1, #0; copy the character from the rear of the string to the temp R3 register STR R2, R1, #0; store the character from register R2 at the R1 location (zero offset) STR R3, R0, #0; store the character from register R3 at the R0 location (zero offset) ADD R0, R0, #1; increment the front pointer by 1 memory location for the next loop ADD R1, R1, #-1; DECREMENT the end pointer by 1 memory location for the next loop ; if R0 is greater than, or equal to R1, then our tracking pointers have passed eachother or are on the same memory location ; in either case, we are done swapping... so jump out of the loop. ; BTW - We could subtract R1-R0, but wed need to change our branch conditional.... Do you know what it would be? ; To evaluate the above conditional we will need to subtract the R1 address from the R0 address: R4 R0 - R1 ; Given R4 R0 - R1, if the result is zero or positive, then R0 is at or beyond R1 ; First, we will need to negate R1... well use R2 to do that, as R2 will be reset at the top of the loop anyway NOT R2, R1; complement R1 and store in R2 ADD R2, R2, #1; add one to complete our negate recipe ; now we have -R1 store in R2 ADD R4, R0, R2; finish R4 R0 - R1 BRzp SWAP_END; branch if zero or positive BR SWAP_START; else repeatSWAP_ENDLEA R0, MY_STRING; get the starting address againPUTS; print the final stringHALTMY_STRING .STRINGZ abcdefNULL_CHAR .FILL #0; the terminating character found at the end of every .STRINGZ string.END /textarea> /div> div idarray2Dcolordersmp classrefContent> h1 classmain-title> Example: Find the address of a row,col location in a 2D Array !span classglyphicon glyphicon-chevron-right myglyphiconSPAN floatRight titlenext onclickupdateVisibility({getlinesmp:true},true)>!/span> span classfloatRight stylefont-size:60%;>Examples/span> span classglyphicon glyphicon-chevron-left myglyphiconSPAN floatRight titleprevious onclickupdateVisibility({restoreregisterssmp:true},true)>/span> /h1> hr> p> In this example, we will write a subroutine that returns the ADDRESS of a specific cell from a 2D array, based on a provided row, col specification. br>br> By convention, we will assume that the array has been stored in column-major form. Meaning, information for the strong>first column is stored contiguously/strong>, followed by information for the second column, etc. This is in contrast to row-major storage, where strong>each rows elements are contiguous in memory/strong>. br>br> Our subroutine will get input and provide output for everything it needs via agreed-upon label names. (we will NOT pass information in and out via registers). br>br> We will take a small tricky shortcut to storing our array of information by using the .STRINGZ directive to put the letters A-Z into memory. We will carefully place that directive at memory location x3001. As you will see from the code below, this will give us a quick way of putting the pre-initialized array contents at an exact location in memory that we can thereafter reference from far away. Note below in the code that we do BRANCH or jump over the memory allocation zone at the beginning of the program with a simple branch instruction; this takes up one memory location, thus our alphabet starts at x3001, and not x3000. br>br> We also need to write (or borrow) a multiplication subroutine. See the sample provided on this site for the Times 10 (looping) sample. This sample is fairly easily modified to loop based on a register value rather than just 10. This provides us with a general purpose multiplication subroutine that multiplies two values in R1 and R2 and stores the result in R0. br>br> We will also implement our basic register store & recall logic (see the Restore Registers Example) to protect the contents of all registers before and after subroutine calls. As you may recall, the approach we recommended can almost be copied and pasted directly into each subroutine with minimal changes (only one label needs to be changed to match the name of your subroutine... but be sure you understand whats going on in that same first!) br>br> /p> span title copy this sample TO the copy buffer onclickdocument.getElementById(array2Dcolordersmp-code).select(); document.execCommand(copy); alert(You can now PASTE into the LC3 Simulator or a text editor.); stylefont-size: 1em; classglyphicon glyphicon-copy>/span> br> textarea idarray2Dcolordersmp-code classtextarea-code>.ORIG x3000BR MAIN; jump over storage below to the start of the main section.STRINGZ ABCDEFGHIJKLMNOPQRSTUVWZYZ; slightly tricky - we are storing a sequence of letters in our 2D array for reference.; The address of the above string STARTS AT x3001,; which you will see is the same as the 2D_ARRAY label value below.; This is essentially our 2D_ARRAY, starting at x3001 and taking up 26 locations,; plus 1 (for the null terminator on the string).; We will assume the 2D array has 13 rows and 2 columns.; Two letters per row and 13 letters per column. 26 letters.; So our NUM_ROW label will be 13 and our NUM_COL label will be 2. (see labels below); We will treat this array as a column-major stored array.; Based on our string above, that means the cells of the first; column (column #0 by our conventions) are: A-M.; And the cells of the second column (column #1) are: N-Z.; If we were storing the array in row-major form, then the cells of the first ROW; would be A, B, and the second ROW would be C, D. Etc.; Like this:;;R\C | 0 | 1 ; ------------; 0 | A | N; 1 | B | O; 2 | C | P; 3 | D | Q; 4 | E | R; 5 | F | S; 6 | G | T; 7 | H | U; 8 | I | V; 9 | J | W; 10 | K | X; 11 | L | Y; 12 | M | Z; such that 2D_ARRAYROW8, COL1 would be the letter V ;----------------------------------------; MAIN;-----------------------------------------MAIN JSR GETADDRESS; get the 2D_ARRAYNUM_ROW,NUM_COL address ; and store it at: ADDRESS_RESULT; ADDRESS_RESULT now has the address of the cell from 2D_ARRAY that we want LDI R0, ADDRESS_RESULT; get the address at ADDRESS_RESULT ; and then get the value at THAT address, and put it in R0 ; above - this is a bit tricky - remember that LDI is a special ; opcode that grabs something from a nearby label that ; has the address of a far away location. In this case, that location ; is the location of our 2D_ARRAY (x3000 in this case). OUT; print out the letter we got from the arrayHALT;---------------------------------; GETADDRESS;-----------------------------------ROW_INDEX .FILL #8; INPUT: the row we wantCOL_INDEX .FILL #1; INPUT: the col we wantNUM_COL .FILL #2; INPUT: number of columns in the arrayNUM_ROW .FILL #13; INPUT: number of rows in the arrayADDRESS_RESULT .FILL x0; OUTPUT: the final address of the requested array cell2D_ARRAY .FILL x3001; INPUT: location of our storage area.blkw #8; register back up zone: room for 8 registersGETADDRESS ; store all registers, note we have to reach back twice as far on each line to reach the next available memory location ST R0, #-2; store R0 at mem-2 from here (in the .blkw section) ST R1, #-4; store R1 at mem-4 from here ST R2, #-6; etc. ST R3, #-8; ST R4, #-10; ST R5, #-12; ST R6, #-14; ST R7, #-16; ; our answer should be: final address base_address + (COL_INDEX * NUM_ROW) + ROW_INDEX LD R1, COL_INDEX; load the value! LD R2, NUM_ROW; load the value! LD R3, ROW_INDEX; LD R4, NUM_COL; LD R5, 2D_ARRAY; load the base ADDRESS of the array. ; above... !! Note that the label is not the address of the array, it is the address where we store the address of the array..... JSR MULT; now we have R0 containing the result of R0 R1 x R2, which is R0 (COL_INDEX * NUM_ROW) ; now to finish the equation, we need to add to R0 the base address of the array (in R5) PLUS the requested ROW_INDEX (in R3) ADD R0, R0, R5; add the base address ADD R0, R0, R3; add the ROW_INDEX ;now R0 has the location (ADDRESS) of the item we want to get from the array ST R0, ADDRESS_RESULT; ; now we need to store R0 (the final address) at ADDRESS_RESULT ; restore all registers LEA R7, GETADDRESS; load the address of this subroutine LDR R0, R7, #-1; recover all registers, in this order! LDR R1, R7, #-2; LDR R2, R7, #-3; LDR R3, R7, #-4; LDR R4, R7, #-5; LDR R5, R7, #-6; LDR R6, R7, #-7; LDR R7, R7, #-8; R7 has to be last, since we overwrite the R7 address offsetRET; return from the call, or we could have done a JMP R5!;---------------------------------; MULT; R0 (OUT) R1 (IN) x R2 (IN);-----------------------------------.blkw #8; register back up zone: room for 8 registersMULT; ... multiplies R1xR2 and stores in R0 ; store all registers, note we have to reach back twice as far on each line to reach the next available memory location ST R0, #-2; store R0 at mem-2 from here (in the .blkw section) ST R1, #-4; store R1 at mem-4 from here ST R2, #-6; etc. ST R3, #-8; ST R4, #-10; ST R5, #-12; ST R6, #-14; ST R7, #-16;AND R0, R0, #0; stort with zero in R0LOOP_STARTADD R0, R0, R1; add R1 for each loopADD R2, R2, #-1; decrement R2 each loopBRnp LOOP_START; loop back if last operation was not zero (R2); else we are done ; restore all registers LEA R7, MULT; load the address of this subroutine ;LDR R0, R7, #-1; DO NOT UPDATE R0.. we want to return the new value LDR R1, R7, #-2;recover all registers, in this order! LDR R2, R7, #-3; LDR R3, R7, #-4; LDR R4, R7, #-5; LDR R5, R7, #-6; LDR R6, R7, #-7; LDR R7, R7, #-8; R7 has to be last, since we overwrite the R7 address offset RET; R0 should have our result .END /textarea> /div> !end of samples> !-- Trigger the modal with a button --> !-- BROWSE MODAL --> div idreferenceModal classmymodal > !-- Modal content --> div classreferenceModal-content onmouseleave/*toggleModal(referenceModal, -1)*/ /*turn off*/> span classmyclose onclicktoggleModal({referenceModal: -1}, true) /*turn off*/>×/span> div classreferenceModal-title>Reference: LC3 Op Codes & Directives/div> h4>Legend: DR destination register R0-R7; SR source register R0-R7; #### numeric literal or LABEL/h4> hr> div classmymodal-categories> div classrow> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleLD DR, ###### Load Direct: Load register DR with VALUE at 9bit offset (-256 to 255) onclickupdateVisibility({LD:true}, true)>LD/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleST SR, ###### Store Direct Store register SR at the 9 bit OFFSET location (-256 to 255) onclickupdateVisibility({ST:true}, true)>ST/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleADD DR, SR, SR ADD DR, SR, ## add 2 source registers or 1 register and a 5 bit value (-16 to 15) onclickupdateVisibility({ADD:true}, true)>ADD/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleBR(n|z|p) OFFSET Branch (conditional) max range: -256 to 255 onclickupdateVisibility({BR:true}, true)>BR (n|p|z)/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleGETC (no args) Get input char from console to R0 (no echo) onclickupdateVisibility({GETC:true}, true)>GETC/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft title.ORIG x3000 Start of code onclickupdateVisibility({ORIG:true}, true)>.ORIG/div> /div> div classrow> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleLDI DR, #### Load Indirect: Load register DR the VALUE at memmemPC* + 9 bit offset with range (-256 to 255) onclickupdateVisibility({LDI:true}, true)>LDI/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleSTI SR, ###### Store Indirect Store the value in register SR at the location MMPC+ 9 bit offset with range (-256 to 255) onclickupdateVisibility({STI:true}, true)>STI/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleAND DR, SR, SR AND DR, SR, ## Bitwise and between 2 registers or 1 register and a 5 bit value (-16 to 15) onclickupdateVisibility({AND:true}, true)>AND/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleJMP R# Jump Register Jump far to the addess contained in the specified register (does NOT set R7) onclickupdateVisibility({JMP:true}, true)>JMP/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleOUT (no args) Print R0 char to console onclickupdateVisibility({OUT:true}, true)>OUT/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft title.FILL ####### Fill 16bit memory location onclickupdateVisibility({FILL:true}, true)>.FILL/div> /div> div classrow> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleLDR DR, SR, ## Load Relative: Load register DR with VALUE AT (SR + 6 bit OFFSET) (-32 to 31) onclickupdateVisibility({LDR:true}, true)>LDR/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleSTR SR, DR, #### Store Relative Store the contents of register SR at the ADDRESS specified by (DR+6 bit offset) (-32 to 31) onclickupdateVisibility({STR:true}, true)>STR/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleNOT DR, SR Bitwise NOT onclickupdateVisibility({NOT:true}, true)>NOT/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleJSR ######## Jump Offset Jump near to the 11 bit offset address (-1024 to 1023). (set R7 for RET) onclickupdateVisibility({JSR:true}, true)>JSR/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titlePUTS (no args) Print R0 String to console onclickupdateVisibility({PUTS:true}, true)>PUTS/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft title.BLKW ##### Initilize memory onclickupdateVisibility({BLKW:true}, true)>.BLKW/div> /div> div classrow> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleLEA DR, ###### Load Effective Address: Load register DR with ADDRESS at 9 bit offset (-256 to 255) (use with .STRINGZ!) onclickupdateVisibility({LEA:true}, true)>LEA/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleJSR R# Jump Register Jump to the address stored in the specified register (set R7 for RET) onclickupdateVisibility({JSRR:true}, true)>JSRR/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleIN (no args) Get input char from console to R0 (do echo) onclickupdateVisibility({IN:true}, true)>IN/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft title.STRINGZ xxxx Initilize memory String onclickupdateVisibility({STRINGZ:true}, true)>.STRINGZ/div> /div> div classrow> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleRET (no args) Return via R7 onclickupdateVisibility({RET:true}, true)>RET/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titlePUTSP (no args) Print R0 String (double chars) onclickupdateVisibility({PUTSP:true}, true)>PUTSP/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft title.END (no args) End of code onclickupdateVisibility({END:true}, true)>.END/div> /div> div classrow> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleRTI (no args) Return from Interrupt (use R6) onclickupdateVisibility({RTI:true}, true)>RTI/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip data-toggletooltip data-placementleft titleHALT (no args) Halt program onclickupdateVisibility({HALT:true}, true)>HALT/div> div classcol-md-2 col-sm-2 referenceModal-text bstooltip>/div> /div> div classrow> div classcol-md-3 col-sm-3 referenceModal-text bstooltip >/div> /div> div classrow> div classcol-md-3 col-sm-3 referenceModal-text bstooltip>/div> /div> /div> /div> /div> !-- BROWSE MODAL --> div idsamplesModal classmymodal > !-- Modal content --> div classreferenceModal-content> span classmyclose onclicktoggleModal({samplesModal: -1}, true) /*turn off*/>×/span> div classreferenceModal-title>LC3 Code Examples/div> h4>Copy/Paste working examples into the simulator. See span classglyphicon glyphicon-question-sign myglyphiconSPAN onclicktoggleModal({aboutModal: 0}, true); stylefont-size:150%> /span> for simulator help. /h4> hr> div classmymodal-categories> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleSay hello sample onclickupdateVisibility({hellosmp:true}, true)>Hello World/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleShift a numeric value left in a register by 1 bit (same as multiplying by 2) onclickupdateVisibility({shiftleftsmp:true}, true)>Shift Left/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleGet a line of character (a string) from user input and store it in memory. onclickupdateVisibility({getlinesmp:true}, true)>Get Line code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> /div> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleGet a character from user input and echo it back to the console onclickupdateVisibility({mimicsmp:true}, true)>Mimic/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleShift an in-memory number right by N bits onclickupdateVisibility({shiftrightsmp:true}, true)>Shift Right code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleInitialize a region of memory with a value onclickupdateVisibility({initarraysmp:true}, true)>Init an Array code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom>/div> /div> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleEcho user input back to the console onclickupdateVisibility({mimic2smp:true}, true)>Mimic 2/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleMultiply a value by 10 through addition onclickupdateVisibility({times10smp:true}, true)>Times 10 (simple)/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleDetermine if a user input character was a letter or a digit onclickupdateVisibility({letterordigitsmp:true}, true)>Letter or Digit? code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> /div> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleImplement a simple for loop onclickupdateVisibility({simpleloopsmp:true}, true)>Simple Loop/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleMultiply a value by 10 using a loop onclickupdateVisibility({times10loopingsmp:true}, true)>Times 10 (looping)/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleSee how to store and load from far away using STI and LDI onclickupdateVisibility({stildismp:true}, true)>STI/LDI - store & load far away code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> /div> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleNegate a value using the complement & +1 method onclickupdateVisibility({negatevaluesmp:true}, true)>Negate a Value/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titlemake a subroutine call and return onclickupdateVisibility({functionsmp:true}, true) >Subroutine Call/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleImplement a simple or operation on two registers onclickupdateVisibility({demorganorsmp:true}, true) >De Morgans OR/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> /div> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleConvert a user-input character to its equivalent numeric value onclickupdateVisibility({char2valuesmp:true}, true)>Character to Value/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleApply a bit mask to test the value of a specific bit: 0 or 1? onclickupdateVisibility({bitmasksmp:true}, true)>Bit Mask/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleSave and restore register values within subroutines. onclickupdateVisibility({restoreregisterssmp:true}, true)>Restore Registers code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom >/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip>/div> /div> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleConvert a string stored in memory into its equivalent numeric value, stored in a register onclickupdateVisibility({string2valuesmp:true}, true)>String to Value code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleSwap the characters in an in-memory string onclickupdateVisibility({reversestringsmp:true}, true)>Reverse String code>new/code>/div> div classcol-md-4 col-sm-4 referenceModal-text bstooltip data-toggletooltip data-placementbottom titleLoad an address from a 2D Array (column major) onclickupdateVisibility({array2Dcolordersmp:true}, true)>2D Array (column major) code>new/code>/div> /div> div classrow> div classcol-md-4 col-sm-4 referenceModal-text bstooltip>/div> /div> /div> /div> /div> div idasciiModal classmymodal > !-- Modal content --> div classasciiModal-content> span classmyclose onclicktoggleModal({asciiModal: -1},true) /*turn off*/>×/span> div classaboutModal-title>ASCII Table/div> hr> div idasciiTable classaboutModal-info> /div> /div> /div> div idopcodeModal classmymodal > !-- Modal content --> div classasciiModal-content> span classmyclose onclicktoggleModal({opcodeModal: -1},true) /*turn off*/>×/span> div classaboutModal-title>Opcode Table/div> hr> div idopcodeTable classaboutModal-info> /div> /div> /div> div idbitscalcHelpModal classmymodal > !-- Modal content --> div classaboutModal-content> span classmyclose onclicktoggleModal({bitscalcHelpModal: -1},true) /*turn off*/>×/span> div classaboutModal-title>Bits Calculator Help/div> hr> div classaboutModal-info> The Bits Calculator will convert in real-time (as you type each character) between decimal, hex, unsigned binary, and twos complement binary notation, while also representing the equivalent ASCII character for the current value.br>br> Note that you can click into or mouse over each input field to see a quick tool tip describing its use. You can also use the strong>up/down arrow keys/strong> on a keyboard to increase or decrease any field value (including ascii) - which is especially helpful to get a better sense of counting in twos complement. If you press strong>SHIFT-arrow-up or SHIFT-arrow-down/strong>, you can instantly jump the to maximum or minimum allowable values for that field.br>br> By convention, hex, and binary are prefixed with the characters x, and b, as is done with LC-3 numeric literals.br>br> To input a negative values for hex, and normal binary (unsigned), simply place a - character AFTER the format indicator. For example: -1 (decimal), x-1 (hex), and b-1 (binary) all represent the value -1.br>br> For twos complement, of course, no sign is allowed, since the left-most bit represents the sign of the value (1 means negative, and 0 means positive). Note that positive values are identical for both normal binary representation (unsigned) and twos complement notation. Only when values become negative will you see a difference in representation between these two binary representations.br>br> The Bits Converter will also show the equivalent ascii character for the current decimal/hex/binary value, if valid. And, you can bring up a quick view of the entire ascii table, if needed.br>br> The converter relies on the bits precision value that you set (defaults to 8 bits) to track overflow values. The min and max values allowed for any numeric format (decimal, hex, binary, twos comp) before overflow is triggered, depend on the specific field you are changing. br>br> For example, if bits 16 (as in LC-3), the MAX positive value that can be represented by 16 bits TWOs COMPLIMENT is 32767, and the MIN value that can be represented is: -32768. Exceeding this range for bits16 will generate an strong>overflow condition in the twos complement field/strong>. (indicated by a strong>!/strong>). br>br> If bits 16, the MAX unsigned value that can be represented in the hex or unsigned binary field is 65535. Since the sign for these fields is tracked separately from the bits themselves in this web tool, you can reach a minimum value of -65535 as well, though such a value could not be expressed in LC-3 with only 16 bits.br>br> Finally, the memory section of the Bits Calculator allows you to easily store the current decimal/hex/binary value in memory. You can also add-to, subtract-from, recall, or clear memory, similar to standard calculators that offer these functions. /div> /div> /div> div idaboutModal classmymodal > !-- Modal content --> div classaboutModal-content > span classmyclose onclicktoggleModal({aboutModal: -1}, true) /*turn off*/>×/span> div classaboutModal-title>About/div> hr> div classaboutModal-info> LC3 Tutor is designed to help you get started quickly with the LC-3 (Little Computer 3) Assembly Language.br>br> Click a onclickupdateVisibility({wcsimGettingStarted : true,}, true)>here/a> or the LC3 Tutor logo in the upper-right corner for quick simulator tips before you start the simulator.br>br> Jump to the LC3 simulator by clicking on the simulator span titleLaunch simulator onclickupdateVisibility({wcsim:true, bitscalc:true}, true); classglyphicon glyphicon-wrench myglyphiconSPAN stylefont-size:100%>/span> icon.br>br> You can jump back and forth between the Simulator, Code Examples, and Opcode span onclicktoggleModal({referenceModal: 0}, true); classglyphicon glyphicon-sunglasses myglyphiconSPAN stylefont-size:100%>/span> pages on this site without losing the current state of your simulated program!br>br> Use the Bits Calculator span titleBits Calculator stylefont-size:100%; data-toggletooltip data-placementtop classbstooltip glyphicon glyphicon-calendar myglyphiconSPAN onclicktoggleModal({bitscalcHelpModal: 0}, true);> /span> to help reinforce your understanding of the relationships between binary, hex, and decimal notations - and the realities of limited bit precision (aka strong>overflow !/strong>).br>br> This site embeds and references the LC-3 Simulator developed by William Chargin, found a hrefhttp://wchargin.github.io/lc3web/ target_blank>here./a>br>br> Reference quick look-up pages for all LC-3 Opcodes, Directives, and Traps.br>br> Explore simple working LC3 coding examples span titleCode Examples onclicktoggleModal({samplesModal: 1}, true); stylefont-size:100%; classglyphicon glyphicon-list myglyphiconSPAN>/span> to understand how opcodes are actually used.br>br> Practice with on-line quizzes span onclickupdateVisibility({QUIZ:true}, true); titleOpen Quiz classglyphicon glyphicon-pencil myglyphiconSPAN stylefont-size:100%>/span> to evaluate your understanding of key concepts. br>br> Recent updates:hr> ul> li>Jun 14, 2017: Added new example: Load an address from a 2D Array stored in Column-Major form./li> li>Jun 7, 2017: Clipboard copy button added to all code samples. Click the icon copy code samples into the copy buffer, and thereafter paste them into an editor of your choice, or the LC3 Simulator on the home page./li> li>Jun 6, 2017: Opcode table added: Launch from next to bits calculator. Click opcodes to jump to the appropriate opcode reference page./li> li>Jun 6, 2017: ASCII table added: Launch from next to bits calculator. Click characters to load bitscalc with the equivalent character value./li> li>Jun 2, 2017: Added new example: Reverse String to reverse the characters in an in-memory string./li> li>Jun 1, 2017: Added new example: Shift Right to convert an in-memory number by shifting it right by N-bits./li> li>May 31, 2017: Added new example: String to Value to convert an in-memory .STRINGZ allocation to a numeric value./li> li>May 28, 2017: Fixed Bits Calculator twos complement conversion error, when entering 2s comp directly, the result was incorrect. This has been fixed./li> li>May 27, 2017: Add LDI (load far) to the existing STI example./li> li>May 26, 2017: Add new example for restore registers to illustrate subroutine register save & restore./li> li>May 25, 2017: Fixes to bits calculator for entry of 2s complement values. Results should be correct now./li> li>May 24, 2017: Added new examples for De Morgans OR, and STI opcode usage./li> li>May 23, 2017: Added basic bits calculator with real-time conversion between decimal, hex, unsigned binary, and 2s complement binary, with fixed bit precision./li> /ul> /div> /div> /div> script> var opcodes { 0001 : AND, 0010 : LD, 1010 : LDI, 0101 : AND, 0110 : LDR, 1110 : LEA, 1001 : NOT, 0011 : ST, 0000 : BR(n|z|p), 1011 : STI, 1100 : JMP/RET, 0111 : STR, 0100 : JSR/JSRR, 1111 : TRAP, 1000 : RTI } var allDIVS { // all divs we want to hide/display from time to time, with initial state LD: false, // initial state is off LDI: false, LDR: false, LEA: false, ST: false, STI: false, STR: false, ADD: false, AND: false, NOT: false, BR: false, JMP: false, JSR: false, JSRR: false, RET: false, RTI: false, GETC: false, OUT: false, PUTS: false, IN: false, PUTSP: false, HALT: false, ORIG: false, FILL: false, BLKW: false, STRINGZ: false, END: false, hellosmp: false, mimicsmp: false, mimic2smp: false, simpleloopsmp: false, negatevaluesmp: false, char2valuesmp: false, shiftleftsmp: false, shiftrightsmp: false, times10smp: false, times10loopingsmp: false, functionsmp: false, demorganorsmp: false, bitmasksmp: false, restoreregisterssmp: false, getlinesmp: false, initarraysmp: false, letterordigitsmp: false, stildismp: false, string2valuesmp: false, reversestringsmp: false, array2Dcolordersmp: false, wcsimGettingStarted: false, //bitscalc: false, QUIZ: false, // qj quiz fptoy: false, // iee float toy vnm: false, // von neumann diagram truth: false, // truth table page wcsim: false }/script> script srclc3tutor.min.js>/script> script> //////////////////////// // BS Tool Tips - OUR ONLY JQUERY USAGE! /////////////////////// $(document).ready(function(){ $(data-toggletooltip).tooltip(); //$(document).tooltip({show: {effect:none, delay:10000}}); //$(document).tooltip({ delay: 10000}); });/script> /body>/html>
View on OTX
|
View on ThreatMiner
Please enable JavaScript to view the
comments powered by Disqus.
Data with thanks to
AlienVault OTX
,
VirusTotal
,
Malwr
and
others
. [
Sitemap
]